Graphics, Figures & TablesMake \cmidrule underneath last heading go to edge of table

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Make \cmidrule underneath last heading go to edge of table

Post by ptrcao »

There is a \cmidrule(l){4-4} underneath the "Name" heading which doesn't follow through to the far extreme of the table. Notice I have not trimmed it the the right.

Code: Select all

\documentclass[12pt]{article}

\usepackage{a4wide} %yeah, I know it's obsolete; just until I learn how to use geometry

\usepackage{booktabs} %for top, middle and bottomline

\usepackage{multirow} %multi column and row spanning

\usepackage{rotating} %enables sidewaystable

\begin{document}

\begin{sidewaystable}[h]
\begin{tabular*}{1\textwidth}{l l l l} %notice the asterisk needed to enable manual width-setting
 \toprule
\multicolumn{4}{c}{Nutritional Modes}\\
\midrule
Energy source & Reducing equivalent source & Carbon source & Name\\
\cmidrule(r){1-1} \cmidrule(l r){2-2}  \cmidrule(l r){3-3}  \cmidrule(l){4-4}
\multirow{4}{*}{Light {\it Photo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Photoorganoheterotroph\\
& & Carbon dioxide -autotroph & Photoorganoautotroph \\
\cmidrule(l r){2-4}
&  \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Photolithoheterotroph\\
& & Carbon dioxide -autotroph & Photolithoautotroph \\ 
\midrule
\multirow{4}{*}{Chemical compounds {\it Chemo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Chemoorganoheterotroph\\
& & Carbon dioxide -autotroph & Chemoorganoautotroph \\
\cmidrule(l r){2-4}
&  \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Chemolithoheterotroph\\
& & Carbon dioxide -autotroph & Chemolithoautotroph\\ 
\bottomrule
\end{tabular*}
\end{sidewaystable}


\end{document}
Last edited by ptrcao on Sat Apr 16, 2011 3:15 am, edited 1 time in total.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)

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
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Make \cmidrule underneath last heading go to edge of table

Post by localghost »

There is no sense in using the starred version of the tabular environment if you don't use its features in the column declaration.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[includeheadfoot,margin=1in]{geometry}  % now you have learned how to use geometry
\usepackage{booktabs}  % for top, middle and bottomline
\usepackage{multirow}  % multi column and row spanning
\usepackage{rotating}  % enables sidewaystable

\begin{document}
  \begin{sidewaystable}
    \centering
    \begin{tabular}{llll} \toprule
      \multicolumn{4}{c}{Nutritional Modes} \\ \midrule
      Energy source & Reducing equivalent source & Carbon source & Name\\
      \cmidrule(r){1-1} \cmidrule(l r){2-2}  \cmidrule(l r){3-3}  \cmidrule(l){4-4}
      \multirow{4}{*}{Light {\it Photo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Photoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Photoorganoautotroph \\ \cmidrule(l r){2-4}
      & \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph &Photolithoheterotroph\\
      & & Carbon dioxide -autotroph & Photolithoautotroph \\ \midrule
      \multirow{4}{*}{Chemical compounds {\it Chemo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Chemoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Chemoorganoautotroph \\ \cmidrule(l r){2-4}
      & \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Chemolithoheterotroph\\
      & & Carbon dioxide -autotroph & Chemolithoautotroph \\ \bottomrule
    \end{tabular}
  \end{sidewaystable}
\end{document}
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Make \cmidrule underneath last heading go to edge of table

Post by ptrcao »

localghost wrote:There is no sense in using the starred version of the tabular environment if you don't use its features in the column declaration.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[includeheadfoot,margin=1in]{geometry}  % now you have learned how to use geometry
\usepackage{booktabs}  % for top, middle and bottomline
\usepackage{multirow}  % multi column and row spanning
\usepackage{rotating}  % enables sidewaystable

\begin{document}
  \begin{sidewaystable}
    \centering
    \begin{tabular}{llll} \toprule
      \multicolumn{4}{c}{Nutritional Modes} \\ \midrule
      Energy source & Reducing equivalent source & Carbon source & Name\\
      \cmidrule(r){1-1} \cmidrule(l r){2-2}  \cmidrule(l r){3-3}  \cmidrule(l){4-4}
      \multirow{4}{*}{Light {\it Photo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Photoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Photoorganoautotroph \\ \cmidrule(l r){2-4}
      & \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph &Photolithoheterotroph\\
      & & Carbon dioxide -autotroph & Photolithoautotroph \\ \midrule
      \multirow{4}{*}{Chemical compounds {\it Chemo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Chemoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Chemoorganoautotroph \\ \cmidrule(l r){2-4}
      & \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Chemolithoheterotroph\\
      & & Carbon dioxide -autotroph & Chemolithoautotroph \\ \bottomrule
    \end{tabular}
  \end{sidewaystable}
\end{document}
It worked. Thanks. :)
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Make \cmidrule underneath last heading go to edge of table

Post by ptrcao »

localghost wrote:There is no sense in using the starred version of the tabular environment if you don't use its features in the column declaration.
This is a sensible observation. :D Though Thorsten, isn't the * necessary if one wants to specify a fixed width for the table? For example I always like to set large tables to have a width equal to \textwidth or \linewidth, so it doesn't exceed the width of the page and violate margins. In that case wouldn't I have no choice but to use the starred version of tabular?

I'd prefer to use regular tabular of course, where possible, but I don't know if it's possible to set a fixed width in regular tabular.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Make \cmidrule underneath last heading go to edge of table

Post by localghost »

ptrcao wrote:[…] isn't the * necessary if one wants to specify a fixed width for the table? For example I always like to set large tables to have a width equal to \textwidth or \linewidth, so it doesn't exceed the width of the page and violate margins. In that case wouldn't I have no choice but to use the starred version of tabular? […]
That is correct. But as already mentioned you then should use the features of this environment. That is to say setting the length \extracolsep to a stretchable value [1]. Here again shown by the known example.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[includeheadfoot,margin=1in]{geometry}  % now you have learned how to use geometry
\usepackage{booktabs}  % for top, middle and bottomline
\usepackage{multirow}  % multi column and row spanning
\usepackage{rotating}  % enables sidewaystable

\begin{document}
  \begin{sidewaystable}
    \centering
    \begin{tabular*}{\textheight}{@{\extracolsep{\fill}}llll} \toprule
      \multicolumn{4}{c}{Nutritional Modes} \\ \midrule
      Energy source & Reducing equivalent source & Carbon source & Name\\
      \cmidrule(r){1-1} \cmidrule(l r){2-2}  \cmidrule(l r){3-3}  \cmidrule(l){4-4}
      \multirow{4}{*}{Light {\it Photo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Photoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Photoorganoautotroph \\ \cmidrule(l r){2-4}
      & \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph &Photolithoheterotroph\\
      & & Carbon dioxide -autotroph & Photolithoautotroph \\ \midrule
      \multirow{4}{*}{Chemical compounds {\it Chemo-}} & \multirow{2}{*}{Organic -organo-} & Organic -heterotroph & Chemoorganoheterotroph \\
      & & Carbon dioxide -autotroph & Chemoorganoautotroph \\ \cmidrule(l r){2-4}
      & \multirow{2}{*}{Inorganic -litho-} & Organic -heterotroph & Chemolithoheterotroph\\
      & & Carbon dioxide -autotroph & Chemolithoautotroph \\ \bottomrule
    \end{tabular*}
  \end{sidewaystable}
\end{document}
But now the original problem returns. Perhaps some trimming of the horizontal rules might do the trick.
ptrcao wrote:[…] I'd prefer to use regular tabular of course, where possible, but I don't know if it's possible to set a fixed width in regular tabular.
Fixed-width tables are possible in many ways [1]. A quite new player in this game is the tabu package which seems to be an allrounder regarding tables.

[1] TeX Frequently Asked Questions - Fixed-width tables
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Make \cmidrule underneath last heading go to edge of table

Post by ptrcao »

localghost wrote: But now the original problem returns. Perhaps some trimming of the horizontal rules might do the trick.
When I compiled your most recently suggested code with tabular starred, the \cmidrule underneath the last heading seemed to extend to the end of the table, so effectively the problem sorted itself out without any trimming modifications?

I think the {@{\extracolsep{\fill}} caused the inter-column space to expand in a way that pushed the last column against the right edge of the table, thus removing the original gap on the far right?

Other unrelated questions:
  • Why do you use \textheight in the width argument?
  • I did some searches and stumbled across \columnwidth, which doesn't seem to mean what I think it means. I take it to mean the present table column width but it's basically interpreted as \linewidth or \textwidth?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Make \cmidrule underneath last heading go to edge of table

Post by localghost »

ptrcao wrote:[…] When I compiled your most recently suggested code with tabular starred, the \cmidrule underneath the last heading seemed to extend to the end of the table, so effectively the problem sorted itself out without any trimming modifications? […]
I observed that not all horizontal rules line up with the right side. Therefore my concerns.
ptrcao wrote:[…] I think the {@{\extracolsep{\fill}} caused the inter-column space to expand in a way that pushed the last column against the right edge of the table, thus removing the original gap on the far right? […]
The extra column separation affects all columns that follow this command in the table column declaration. See link to the TeX FAQ.
ptrcao wrote:[…] Other unrelated questions:
  • Why do you use \textheight in the width argument?
  • I did some searches and stumbled across \columnwidth, which doesn't seem to mean what I think it means. I take it to mean the present table column width but it's basically interpreted as \linewidth or \textwidth?
  • Since the table is going to appear in landscape orientation, its width becomes its height when printed in a portrait document. Therefore the length \textheight to make it fill the page.
  • In two-columned documents the line width is maintained in the length register \columnwidth. It is calculated from the text width minus the distance \columnsep between the columns. It is identical with \textwidth and \linewidth in a single-column document. \linewidth can vary inside several environments like minipage, where it is determined by the given width. The same applies to the \parbox command.
Post Reply