In LaTeX tables, is there a way to modify \specialrule
to cover only few columns or should I just use \cmidrule
? Thanks
[Tex/LaTex] Modifying specialrule to cover fewer columns
tables
Related Solutions
To get different alignments in some cells of a tabular
, you can wrap the cells in a \multicolumn
(see Change alignment for individual table rows). PGFPlotstable provides a key for doing this automatically for the header row using the key multicolumn names
, which takes an optional argument for the alignment. multicolumn names=l
would left-align the header, for instance. The default is c
, which centers the text:
\documentclass{article}
\usepackage{pgfplotstable}
\begin{document}
\begin{table}[H]
\centering
\caption{Stuff}
\pgfplotstabletypeset[
col sep=comma,
string type,
every head row/.style={before row=\hline,after row=\hline},
every last row/.style={after row=\hline},
display columns/0/.style={column name = Years, column type = {r}},
display columns/1/.style={column name = Data1, column type = {r}},
display columns/2/.style={column name = Data2, column type = {r}},
multicolumn names
]{
A, B, C
DDDDD, EEEEEEE, FFFFFFF
GGGG, HH, III
}
\end{table}
\end{document}
Tables in LaTeX require a specification for the exact number of columns the table has. This is given in the argument to the \begin{tabular}
environment.
In your table, you have specified {llr}
which means the table has three columns. If you want five columns you need something like {llrll}
(since your decimal column is the one you want right-aligned.)
For most tables, the booktabs
package is really useful. It provides nicer vertical spacing and different width rules for tops and middle parts of the table. I've used it in the code below.
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{llrll}
\toprule
Gastro & Grade 1 & Grade 2 & Grade 3 & Grade 4 \\
\midrule
Gnat & per gram & 13.65 & Grade 3 & Grade 4 \\
& each & 0.01 & Grade 3 & Grade 4 \\
Gnu & stuffed & 92.50 & Grade 3 & Grade 4 \\
Emu & stuffed & 33.33 & Grade 3 & Grade 4 \\
Armadillo & frozen & 8.99 & Grade 3 & Grade 4 \\
\bottomrule
\end{tabular}
\end{document}
Possible values for the column specification are:
l = left aligned column
r = right aligned column
c = center aligned column
p{<width>} = left aligned column of <width>
There are more complex column specifications, but these are the basics. See the following questions for some more details:
Best Answer
According to the booktabs manual (section 5 page 6), the trimming of
toprule
,midrule
,bottomrule
andspecialrule
is available if you typeset your tabular using longtable.As you will see, you change the number inside the parenthesis
(l{<len>}r{<len>})
. You may calculate the length withdimexpr
or calc, but unless all your columns is of fixed width (or manually calculated), you probably have to do some eyeballing and trials before you find the right trimming factor. I added some colour as a bonus.Using
\cmidrule[wd](trim){a-b}
is another option, both inlongtable
and ordinarytabular
.longtable is a stable and advanced package. And it is no problem to typeset all your tables as longtables. However, be aware that
longtable
does not float, so never place alongtable
inside a table environment. So if you need floating tables, use\cmidrule
. However, then neither\toprule
,\specialrule
nor\bottomrule
can be trimmed in antabular
environment.