Graphics, Figures & TablesTable Lines and Caption Position

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
moh-thabit
Posts: 12
Joined: Wed Mar 13, 2013 3:16 pm

Table Lines and Caption Position

Post by moh-thabit »

Before I put my question, I searched in forum to find solution, I didn't get the answer. I am using a conference, IEEEtran document class as in this code.

Code: Select all

\documentclass[conference]{IEEEtran}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{setspace}
\usepackage{hyperref}
\usepackage{float}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage[switch, modulo]{lineno} % line numbering
\usepackage{epstopdf} % figures eps 
\usepackage{amsmath}

\begin{document}
  \begin{table}
    \scriptsize
    \begin{tabular}{llllllll}\toprule 
      Bus & Voltage & Angle & \multicolumn{2}{c}{Load} & \multicolumn{2}{c}{Generation} & Injected \\ \cline{4-5} \cline{6-7}
      No. & (p.u)   & (deg)   & MW &    MVar   &   MW   & MVar     & MVar  \\ \midrule
      1   &  1.040  &  0.0    &  0    &    0   &   71.594  &  27.032  &    0   \\
      2   &  1.025  &  9.279  &    0    &    0   &   163.0   &   6.657  &    0   \\
      3   &  1.025  &  4.664  &    0    &    0   &    85.0   & -10.856  &    0   \\
      4   &  1.026  & -2.217  &    0    &    0   &     0     &    0     &    0   \\
      5   &  0.996  & -3.989  &   125   &   50   &     0     &    0     &    0   \\
      6   &  1.013  & -3.688  &    90   &   30   &     0     &    0     &    0   \\
      7   &  1.026  &  3.719  &    0    &    0   &     0     &    0     &    0   \\
      8   &  1.016  &  0.727  &   100   &   35   &     0     &    0     &    0   \\
      9   &  1.032  &  1.966  &    0    &    0   &     0     &    0     &    0   \\
      Total &         &         &  315.0  &  115.0 &  319.954  &  22.833  &        \\ \bottomrule
    \end{tabular}
    \caption {Load flow results}
    \label{Load flow}
  \end{table}
\end{document}


My output table is shown:
table-output.png
table-output.png (29.74 KiB) Viewed 23176 times
I want to have a copy like in figure below, I did the same except the lines not separated between "Load" and "Generation" in \toprule, how I can make the line separated?
table-wanted.png
table-wanted.png (29.27 KiB) Viewed 23176 times
Other problem is the caption is more close to table, how I can make it little more down?
Last edited by localghost on Tue Jun 04, 2013 6:18 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table Lines and Caption Position

Post by Johannes_B »

Hi there,

have a look at the example I adapted from your code.

Code: Select all

\documentclass[conference]{IEEEtran}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
  \begin{table}
%   \scriptsize
    \caption {Load flow results}
    \label{Load flow}
    \begin{tabular}{lSSSSSSl}\toprule
      {Bus} & {Voltage} & {Angle} & \multicolumn{2}{c}{Load} & \multicolumn{2}{c}{Generation} & {Injected} \\ \cmidrule(lr){4-5} \cmidrule(lr){6-7}
      No. & {(p.u)} & {(deg)} & {MW} & {MVar} & {MW} & {MVar} & {MVar} \\ \midrule
      1 & 1.040 & 0.0 & 0 & 0 & 71.594 & 27.032 & 0 \\
      2 & 1.025 & 9.279 & 0 & 0 & 163.0 & 6.657 & 0 \\
      3 & 1.025 & 4.664 & 0 & 0 & 85.0 & -10.856 & 0 \\
      4 & 1.026 & -2.217 & 0 & 0 & 0 & 0 & 0 \\
      5 & 0.996 & -3.989 & 125 & 50 & 0 & 0 & 0 \\
      6 & 1.013 & -3.688 & 90 & 30 & 0 & 0 & 0 \\
      7 & 1.026 & 3.719 & 0 & 0 & 0 & 0 & 0 \\
      8 & 1.016 & 0.727 & 100 & 35 & 0 & 0 & 0 \\
      9 & 1.032 & 1.966 & 0 & 0 & 0 & 0 & 0 \\[5pt]
      Total & & & 315.0 & 115.0 & 319.954 & 22.833 & \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
The code button is extremely useful, it gives code markup and the ability to click on "Open with writeLaTeX". This ensures all of us seeing the same output.

Note the use of the siunitx package to align the numbers.
Last edited by Johannes_B on Tue Jun 04, 2013 6:37 pm, edited 1 time in total.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Table Lines and Caption Position

Post by localghost »

moh-thabit wrote:[…] Other problem is the caption is more close to table, how I can make it little more down?
Tables have their captions above. And the class formats them correspondingly. So just put them there. Take a look at the IEEEtran manual to see how captions are placed for tables.


Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Table Lines and Caption Position

Post by Johannes_B »

Sorry, I completely missed the caption part. Thorsten is right, a table caption goes on top.
I corrected my former post.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
moh-thabit
Posts: 12
Joined: Wed Mar 13, 2013 3:16 pm

Re: Table Lines and Caption Position

Post by moh-thabit »

Thank very much for both of you Johannes_B and localghost.

It works now but the table is span to the other column, how I control the size of table?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table Lines and Caption Position

Post by Johannes_B »

Well, you could span it over both columns in the first place and center it.

Code: Select all

\documentclass[conference]{IEEEtran}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{blindtext}
\begin{document}
\blindtext[12]
\begin{table*}[tb]
  \centering
  % \scriptsize
    \caption {Load flow results}
    \label{Load flow}
    \begin{tabular}{lSSSSSSl}\toprule
      {Bus} & {Voltage} & {Angle} & \multicolumn{2}{c}{Load} & \multicolumn{2}{c}{Generation} & {Injected} \\ \cmidrule(lr){4-5} \cmidrule(lr){6-7}
      No. & {(p.u)} & {(deg)} & {MW} & {MVar} & {MW} & {MVar} & {MVar} \\ \midrule
      1 & 1.040 & 0.0 & 0 & 0 & 71.594 & 27.032 & 0 \\
      2 & 1.025 & 9.279 & 0 & 0 & 163.0 & 6.657 & 0 \\
      3 & 1.025 & 4.664 & 0 & 0 & 85.0 & -10.856 & 0 \\
      4 & 1.026 & -2.217 & 0 & 0 & 0 & 0 & 0 \\
      5 & 0.996 & -3.989 & 125 & 50 & 0 & 0 & 0 \\
      6 & 1.013 & -3.688 & 90 & 30 & 0 & 0 & 0 \\
      7 & 1.026 & 3.719 & 0 & 0 & 0 & 0 & 0 \\
      8 & 1.016 & 0.727 & 100 & 35 & 0 & 0 & 0 \\
      9 & 1.032 & 1.966 & 0 & 0 & 0 & 0 & 0 \\[5pt]
      Total & & & 315.0 & 115.0 & 319.954 & 22.833 & \\ \bottomrule
    \end{tabular}
  \end{table*}
  \blindtext[12]
\end{document}
You could change the size, but I wouldn't recommend it in you case.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

Table Lines and Caption Position

Post by localghost »

moh-thabit wrote:[…] It works now but the table is span to the other column, how I control the size of table?
There are some measures you can take to evade this.
  • In your example you have already decreased the font size by \scriptsize. Johannes seemingly commented this in his example.
  • Johannes already introduced the S columns by siunitx. If you explicitly set the digit format for each column, only the necessary horizontal space is reserved.
  • Modify the length \tabcolsep (default value 6pt) which determines the horizontal gap between the table columns.
All these points are incorporated in the below example.

Code: Select all

\documentclass[conference]{IEEEtran}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{lipsum}  % only for dummy text, not for use in actual document

\begin{document}
  \lipsum[1-2]   % only for dummy text, not for use in actual document

  \begin{table}[!htb]
    \caption{Load flow results}
    \label{tab:loadflow}
    \centering\scriptsize
    \setlength{\tabcolsep}{4pt}  % determines gap between columns
    \begin{tabular}{
      r
      S[table-format=1.3]
      S[table-format=-1.3]
      S[table-format=3.0]
      S[table-format=3.0]
      S[table-format=3.3]
      S[table-format=-2.3]
      c}\toprule
      {Bus} & {Voltage} & {Angle} & \multicolumn{2}{c}{Load} & \multicolumn{2}{c}{Generation} & {Injected} \\ \cmidrule(lr){4-5} \cmidrule(lr){6-7}
      No.   & {(p.u)} & {(deg)} & {MW} & {MVar} & {MW} & {MVar} & {MVar} \\ \midrule
      1     & 1.040 &  0.0   &   0 &   0 &  71.594 &  27.032 & 0 \\
      2     & 1.025 &  9.279 &   0 &   0 & 163     &   6.657 & 0 \\
      3     & 1.025 &  4.664 &   0 &   0 &  85     & -10.856 & 0 \\
      4     & 1.026 & -2.217 &   0 &   0 &   0     &   0     & 0 \\
      5     & 0.996 & -3.989 & 125 &  50 &   0     &   0     & 0 \\
      6     & 1.013 & -3.688 &  90 &  30 &   0     &   0     & 0 \\
      7     & 1.026 &  3.719 &   0 &   0 &   0     &   0     & 0 \\
      8     & 1.016 &  0.727 & 100 &  35 &   0     &   0     & 0 \\
      9     & 1.032 &  1.966 &   0 &   0 &   0     &   0     & 0 \\ \addlinespace
      Total &       &        & 315 & 115 & 319.954 &  22.833 &   \\ \bottomrule
    \end{tabular}
  \end{table}
  
  \lipsum[3-8]  % only for dummy text, not for use in actual document
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Post Reply