One way to do this would be to use pgfplotstable
as in the example that follows. If you need to do more complex analysis, you can create a csv file that can be editted in excel and imported using pgfplotstable
or datatool
package. You will find quite a few examples of it under datatool
and pgfplotstable
tag.
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\pgfplotstableread[col sep = comma]{
x,y,
1,6,
2,4,
3,5,
4,7,
5,8,
} \data
\begin{table}
\pgfplotstableset{create on use/a/.style={create col/expr={\thisrow{x}+\thisrow{y}}}}
\pgfplotstableset{create on use/b/.style={create col/expr={\thisrow{x}-\thisrow{y}}}}
\pgfplotstableset{create on use/c/.style={create col/expr={(\thisrow{x}+\thisrow{y})/2}}}
\pgfplotstabletypeset[columns={x,y,a,b,c},
columns/x/.style={column name={$x$}, column type={c}, },
columns/y/.style={column name={$y$}, column type={c}, },
columns/a/.style={column name={$x+y$}, column type={c}, },
columns/b/.style={column name={$x-y$}, column type={c}, },
columns/c/.style={column name={$(x+y)/2$}, column type={c}, },
]{\data}
\end{table}
\end{document}
The following example adds some more eye-candy and illustrates how to import data from a file.
\documentclass{article}
\usepackage{pgfplotstable} % Typeset table and manipulate column entries
\usepackage{booktabs} % Nicer horizontal rules for tables
%\usepackage{array} % To align column entries by decimal separator
\usepackage{filecontents} % To illustrate importing data from external file
\begin{filecontents*}{data.csv} % Sample contents of data.csv file
x, y,
1, 6,
2, 4,
3, 5,
4, 7,
5, 8,
4.4, 7,
512, 81,
\end{filecontents*}
\pgfplotstableread[col sep = comma]{data.csv}\data
\begin{document}
\begin{table}[h]
\pgfplotstableset{create on use/a/.style={create col/expr={ \thisrow{x}+\thisrow{y}}}}
\pgfplotstableset{create on use/b/.style={create col/expr={ \thisrow{x}-\thisrow{y}}}}
\pgfplotstableset{create on use/c/.style={create col/expr={(\thisrow{x}+\thisrow{y})/2}}}
\pgfplotstabletypeset%
[columns={x,y,a,b,c},
every head row/.style={before row=\toprule, after row=\midrule},
every nth row={5}{before row=\midrule},
every last row/.style={after row=\bottomrule},
columns/x/.style={column name={$x$}, dec sep align},
columns/y/.style={column name={$y$}, dec sep align},
columns/a/.style={column name={$x+y$}, dec sep align},
columns/b/.style={column name={$x-y$}, dec sep align},
columns/c/.style={column name={$\frac{x+y}{2}$}, dec sep align},
]{\data}
\end{table}
\end{document}
The type you are looking for is tcb@cnt@mintedbox
:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{minted}
\usepackage{cleveref}
\newminted[mycsharp]{csharp}{tabsize=2,fontsize=\footnotesize}
\newminted[myjson]{js}{tabsize=2,fontsize=\footnotesize}
\newminted[myxml]{xml}{tabsize=2,fontsize=\footnotesize}
\newminted[myshell]{shell-session}{tabsize=2,fontsize=\footnotesize}
\newminted[mycode]{text}{tabsize=2,fontsize=\footnotesize}
\newtcolorbox[auto counter,number within=section,
list inside=mypyg]{mintedbox}[2][]{%
title={Listing \thetcbcounter: #2},
list entry={\numberline{\thetcbcounter}#2},
enhanced,colframe=red!50!black,drop fuzzy shadow,#1}
\newenvironment{listingsbox}[3][]
{%
\def\listingsboxenvironment{#2}%save the environments
\VerbatimEnvironment%
\begin{mintedbox}[#1]{#3}%
\begin{\listingsboxenvironment}}%
{%
\end{\listingsboxenvironment}%
\end{mintedbox}%
}
\makeatletter
\crefname{tcb@cnt@mintedbox}{minted listing}{minted listings}
\Crefname{tcb@cnt@mintedbox}{Minted listing}{Minted listings}
\makeatother
\begin{document}
\section{Test}
\Cref{lst:agent:logstash:configuration} and \cref{lst:agent:logstash:configuration}.
\Cref{lst:agent:logstash:configuration,lst:test} and \cref{lst:agent:logstash:configuration,lst:test}.
\begin{listingsbox}[label={lst:agent:logstash:configuration}]{myshell}{A nice title}
[root@localhost ~]# vi /etc/sysconfig/network
\end{listingsbox}
\begin{listingsbox}[label={lst:test}]{myshell}{Something else}
[root@localhost ~]# vi /etc/sysconfig/something
\end{listingsbox}
\end{document}
The type can be easily obtained examining the output console; if you process my code without the \crefname
, \Crefname
lines, you will get several warnings like this one:
LaTeX Warning: cref reference format for label type `tcb@cnt@mintedbox' undefi
ned on input line 33.
And the messages show the type that has to be used in \crefname
.
Best Answer
As already suggested in one of the comments, to achieve your objective you should load the cleveref package and type
Assuming these tables are numbered 1, 2, and 3, respectively, and assuming you're writing in English, you'll get
where "--" is supposed to represent an en-dash. (The conjuction particle is actually configurable; if one states
\newcommand{\crefrangeconjunction}{ to~}
in the preamble, one would get "Tables 1 to 3" instead ofTables 1--3
.)Note that you needn't actually enter the labels in consecutive order; if you'd written
\cref{table2,table3,table1}
, you'd still have gotten "Tables 1--3".The package does impose an important restriction on the characters permitted in labels: since
,
is used as the separator between labels that form the the argument of\cref
, you can't use,
as a component of a label.