Graphics, Figures & Tablesvertical separator line with tabularx

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

vertical separator line with tabularx

Post by carol »

Hi,
The vertical separator line specified by | doesn't seem to be end-to-end with respect to horizontal lines. An example is provided below. Where does the problem come from?

thanks

PS. the first column on right is extra but doesn't disturb the demonstration.

Code: Select all

\documentclass[12pt,twoside,a4paper]{report}
\usepackage{graphicx}

\usepackage{booktabs,tabularx}

\begin{document}
\begin{table}[h]
{\tiny
 \begin{tabularx}{\linewidth}{|c|c|c|}
\toprule
\addlinespace
h16&h2&h3\\\addlinespace\hline\hline
\addlinespace
r1&2c&1c\\\addlinespace\hline

r2&c11&c22\\
\bottomrule
\end{tabularx}
}
\end{table}

\end{document}

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

vertical separator line with tabularx

Post by localghost »

The booktabs package doesn't like vertical lines because it tries to produce readable tables without them.


Best regards
Thorsten
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

Re: vertical separator line with tabularx

Post by carol »

I removed booktabs from the list of packages but I got the following error:

Undefined control sequence \end{tabularx}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

vertical separator line with tabularx

Post by localghost »

Removing the package was no good idea. Omitting the vertical lines is the better one. The error is no surprise since your are using commands from booktabs in your table.
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

Re: vertical separator line with tabularx

Post by carol »

All right. But how to separate the cells if I want to have cell-based table?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

vertical separator line with tabularx

Post by localghost »

Keep the vertical lines and don't use booktabs.
carol
Posts: 105
Joined: Wed Dec 24, 2008 7:25 pm

Re: vertical separator line with tabularx

Post by carol »

So since tabularx doesn't work without booktabs, I have no choice except using tabular. How to replace \toprule, \midrule, \bottomrule that are used with tabularx to have solid thick line?

Cheers,
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

vertical separator line with tabularx

Post by localghost »

carol wrote:So since tabularx doesn't work without booktabs, I have no choice except using tabular. [...]
Nobody claimed that. But you are not using the column features of tabularx in your example. A simple tabular* environment would do also.
carol wrote: How to replace \toprule, \midrule, \bottomrule that are used with tabularx to have solid thick line? [...]
Just use the features for horizontal lines of the standard tabular environment.

Code: Select all

\documentclass[12pt,a4paper,twoside,english]{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont={bf,sf},tableposition=top]{caption}

\begin{document}
  \begin{table}[!ht]
    \renewcommand{\arraystretch}{1.2}
    \caption{Table caption}\label{tab:table}
    \centering
    \tiny
    \begin{tabular}{|c|c|c|}\hline
      h16 & h2 & h3 \\\hline\hline
      r1 & 2c & 1c \\\hline
      r2 & c11 & c22\\\hline
   \end{tabular}
  \end{table}
\end{document}
You can control the line width by modifying the length \arrayrulewidth. You could also try the hhline package.
Post Reply