Graphics, Figures & TablesVertical Lines exceed Table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
adhraklasoon
Posts: 6
Joined: Sun Sep 09, 2012 6:08 pm

Vertical Lines exceed Table

Post by adhraklasoon »

Hi all,

I've got two rather simple tables. The data is all in the right place, but the vertical lines exceed the end of both tables. Also I have no vertical line at the end of first row of the second table. I'm sorry to post such a primitive question. Even tried to search the forum, but failed. So thought it would be much much easier to just ask an expert to help me out.

Please find attached source and output files.

Thank you!
Sonia
Attachments
samplefile.pdf
(35.2 KiB) Downloaded 222 times
samplefile.tex
(1.37 KiB) Downloaded 205 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Vertical Lines exceed Table

Post by cgnieder »

Hi Sonia,

This is the cause of your problems: don't put the \label inside the tabular. It can't label anything there since it needs to follow \caption and worse: it starts a new cell. In your second table the \multicolumns only span two cells instead of three which is why you're missing two cells in that line.

Since you're mentioning aesthetics I'd suggest a few things:
  • use less vertical lines, I'd use none
  • you're loading booktabs; use it
  • use siunitx for the alignment of the numbers.
Putting this together for your example:

Code: Select all

\documentclass{article}
\usepackage{booktabs,siunitx}
\setlength\heavyrulewidth{1pt}
\begin{document}

\begin{table}[ht]
 \centering\small
 \caption{insert caption here}\label{UM_result1}
 \begin{tabular}{l*5{S[table-format=2.1]}}
  \toprule
        & \multicolumn{2}{c}{Men}     & \multicolumn{2}{c}{Women}   \\
  \cmidrule(lr){2-3}\cmidrule(lr){4-5}
   Age  & {Leg (n=34)} & {Arm (n=14)} & {Leg (n=29)} & {Arm (n=12)} \\
   Mean & 45.0         & 30.3         & 37.0         & 25.8         \\
   SD   & 21.5         & 8.1          & 18.0         & 5.8          \\
   Min  & 19.0         & 24.0         & 20.0         & 21.0         \\
   Max  & 84.0         & 46.0         & 76.0         & 42.0         \\
  \bottomrule
 \end{tabular}
\end{table}

blhablah blha
blah blha blha

\begin{table}[ht]
 \centering\small
 \caption{insert caption here}\label{UM_result2}
 \begin{tabular}{
   l
   *2{
   S[table-space-text-post=\,\% *,table-format=2]
   S[table-format=1.2]
   S[table-format=1.2]
   }
  }
  \toprule
                  & \multicolumn{3}{c}{Leg model}  & \multicolumn{3}{c}{Arm model} \\
  \cmidrule(lr){2-4}\cmidrule(lr){5-7}
                  & {Mean difference} & {$r$}   & {$r^2$}  & {Mean difference} & {$r$} & {$r^2$} \\
   Mass           & 2\,\%           & 0.39  & 0.15   & 37\,\% *          & 0.64  & 0.41  \\
   Mass-Fat       & 7\,\% *         & 0.60  & 0.36   & 36\,\% *          & 0.89  & 0.80  \\
   Regression     & 0\,\%           & 0.68  & 0.46   & 2\,\%             & 0.92  & 0.85  \\
   Approximation  & 1\,\%           & 0.88  & 0.78   & 0\,\%             & 0.99  & 0.99  \\
  \bottomrule
 \end{tabular}
\end{table}

\end{document}
aesthetics.png
aesthetics.png (27.8 KiB) Viewed 3166 times
Regards
site moderator & package author
adhraklasoon
Posts: 6
Joined: Sun Sep 09, 2012 6:08 pm

Re: Vertical Lines exceed Table

Post by adhraklasoon »

Wow! I got an even better reply than expected! Thank you Clemens :)
Post Reply