# Vertical lines within cell

I'm trying to replicate the folowing table in LaTeX with booktabs:

However, I have trouble making the vertical lines. Here's what I have so far:

\begin{tabularx}{\textwidth}{l | c c c c c c c c c c c c}
\toprule
& \ce{NH4^{+}} & \ce{Na+} & \ce{K+} & \ce{Mg^{2+}} & \ce{Zn^{2+}} & \ce{Cu^{2+}} & \ce{Fe^{2+}} & \ce{Fe^{3+}} & \ce{Ca^{2+}} & \ce{Ba^{2+}} & \ce{Pb^{2+}} & \ce{Ag^{+}} \\
\midrule
\ce{NO3^{-}} & L & L & L & L & L & L & L & L & L & L & L & L \\ \cmidrule(r){12-13}
\ce{Cl-} & L & L & L & L & L & L & L & L & L & L & T & T \\
\ce{Br-} & L & L & L & L & L & L & L & L & L & L & T & T \\
\ce{I-} & L & L & L & L & L & L & L & L & L & L & T & T \\
\bottomrule
\end{tabularx}


Which gives this:

There's a small gap highlighted with the red circle, which I don't want to have.

How do I a) make vertical lines in the table such as in the original and b) prevent the small gap due to to the "local" horizontal lines, preferebly using booktabs.

• booktabs by design makes it hard to have vertical lines. use \cline rather than \cmidrule – David Carlisle Jan 8 '15 at 11:44

booktabs is not meant to be used with vertical lines. Therefore, I would leave them away and just use some \multicolumns where you need the separator line. This could look like this.

% arara: pdflatex

\documentclass{article}
\usepackage{booktabs}
\usepackage{mhchem}

\begin{document}
\begin{tabular}{l *{12}c}
\toprule
& \ce{NH4^{+}} & \ce{Na+} & \ce{K+} & \ce{Mg^{2+}} & \ce{Zn^{2+}} & \ce{Cu^{2+}} & \ce{Fe^{2+}} & \ce{Fe^{3+}} & \ce{Ca^{2+}} & \ce{Ba^{2+}} & \ce{Pb^{2+}} & \ce{Ag^{+}} \\
\midrule
\ce{NO3^{-}} & L & L & L & L & L & L & L & L & L & L & L & L \\ \cline{12-13}
\ce{Cl-} & L & L & L & L & L & L & L & L & L & L & \multicolumn{1}{|c}{T} & T \\
\ce{Br-} & L & L & L & L & L & L & L & L & L & L & \multicolumn{1}{|c}{T} & T \\
\ce{I-} & L & L & L & L & L & L & L & L & L & L & \multicolumn{1}{|c}{T} & T \\ \cline{10-11}
\ce{SO4^{2-}} & L & L & L & L & L & L & L & L & \multicolumn{1}{|c}{T} & T & T & T\\
\bottomrule
\end{tabular}
\end{document}


Note that you will have to reduce the size as it is bigger than the text width. You could rotate it or use some other trick you find on this homepage. There is no use in using tabularx when not using the X columns. As you have seen in your MWE, the lines are ending at \textwidth, but the table content isn't.

• Neat, thanks! I didn't knew you could make x columns just like that within tabular(x). – Argo Jan 8 '15 at 16:30