3

I'm trying to typeset a Word doc in LaTeX - mainly so that I can get the results I want, rather than Word (or LibreOffice) making my decisions for me. And my current difficulty consists of a few tables. One has cells with different widths in its rows:

-----------
|  |      |
-----------
|      |  |
-----------
|      |  |
-----------
|  |      |
-----------

I can get this effect with lots of multicolumns, or by doing it with TiKZ, but I would have thought there'd be an easier way. In fact, one table I have is perfectly regular, except for one cell which is divided in two, like in this second row:

-------------
|   |       |
-------------
|   |   |   |
-------------
|   |       |
-------------
|   |       |
-------------

What's the best way: tabular (or one of its variants) with multicolumn, TiKZ, or something else?

2 Answers 2

3

This approach places a faux column divider where you want, using \vlyn (which adds \tabcolsep gap around a \vline). Using a judicious combination of actual columns and faux columns, you should be able to achieve your aim.

\documentclass{article}
\newcommand\vlyn{%
  \hspace{\tabcolsep}%
  \vline%
  \hspace{\tabcolsep}%
}
\begin{document}
\begin{tabular}{|c|}
\hline
a\vlyn bcd\\
\hline
abc\vlyn d\\
\hline
abc\vlyn d\\
\hline
a\vlyn bcd\\
\hline
\end{tabular}

\begin{tabular}{|c|c|}
\hline
a& bcd\\
\hline
a& bcd\\
\hline
a& bc\vlyn d\\
\hline
a& bcd\\
\hline
\end{tabular}
\end{document}

enter image description here

3
  • Oh I'd completely forgotten all about \vline - that's great! Can you split a cell (using \vline) into small cells of specified widths?
    – Alasdair
    Aug 15, 2013 at 11:37
  • @Alasdair I renamed it \vlyn (it was my own macro), so as not to destroy TeX's own \vline, and so that I could automatically add \tabcolsep gap around it. See revision. Aug 15, 2013 at 11:42
  • @Alasdair For sub-columns of specified width, I would put the text into a \makebox of the specified width. In such cases, you may have to omit the additional \tabcolsep gap by using \vline directly, rather than \vlyn. Aug 15, 2013 at 11:46
1

I tried to create you tables using the cals tables. Although the variable number and size of columns is not supported, with hacks it works:

variable number of columns

\documentclass{article}
\usepackage{cals}
\begin{document}
\makeatletter
\def\cals@framers@width{.4pt}

Table 1\par\smallskip
\begin{calstable}
\colwidths{{1cm}{2cm}}
\brow \cell{a} \cell{bcd} \erow
\colwidths{{2cm}{1cm}}
\brow \cell{abc} \cell{d} \erow
\brow \cell{abc} \cell{d} \erow
\colwidths{{1cm}{2cm}}
\brow  \cell{a} \cell{bcd} \erow
\end{calstable}

\bigskip

Table 2\par\smallskip
\begin{calstable}
\colwidths{{1cm}{2cm}}
\brow \cell{a} \cell{bcd} \erow
\brow \cell{a} \cell{bcd} \erow
\colwidths{{1cm}{1cm}{1cm}}
\brow \cell{a} \cell{bc} \cell{d} \erow
% hack displays and forgets the row separation above
\lastrule \let\cals@last@context=n
\colwidths{{1cm}{2cm}}
\brow \cell{a} \cell{bcd} \erow
\end{calstable}


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .