12

How to draw such table in tabular: enter image description here

even in the Word, I can only generate a 6*2 table then merge each column respectively.

I prefer use the two table method since it is easy to understand and much compatible with other code. But I happened to a new problem in my real situation enter image description here

There is a additional row at the top of each table, their height should be equal. Then how to do this using two table method and need I accept the answer here then open o new question?

5
  • 2
    Why not creating two tables and putting them side by side? Jun 27, 2018 at 10:32
  • 2
    Other than starting and ending at the same (vertical) place, do the two columns share any other constraints, such as all cells in a given column are of fixed height? Jun 27, 2018 at 10:32
  • 3
    It would be helpful to know what you need this for; because this seems like a really bad idea for a table (I recommend you read the “booktabs” vignette, which explains how tables should be used properly). On the other hand, it might be an acceptable chart (rather than a table). This will necessitate a quite different technical solution in LaTeX though (e.g. using TikZ). Jun 27, 2018 at 16:58
  • What's 'the two table method'? What code do you have? Why have you edited your question in a way which renders existing answers inevitably incomplete? Please ask a new question and include a minimal working example, linking this question if appropriate.
    – cfr
    Jun 28, 2018 at 2:10
  • @cfr ok, I will open a new question. Jun 28, 2018 at 2:11

6 Answers 6

16

Use nested tabulars:

\documentclass{article}
\begin{document}

\begin{tabular}{|@{} l @{}|@{} c @{}|}\hline
  \begin{tabular}{ l }
    some text in the left\\\cline{1-1}
    some more text in the left column\\
  \end{tabular}
&  
  \begin{tabular}{ l }
    some text in the left\\\hline
    some text in the left\\\hline
    some more text in the left column
\end{tabular}\\\hline
\end{tabular}

\end{document}

enter image description here

or with

\begin{tabular}{|@{} c @{}|@{} c @{}|}\hline
    \renewcommand\arraystretch{1.8}%    <====
    \begin{tabular}{ l }

enter image description here

6
  • Why is the vertical alignment in the 2-row left column inconsistent, and is there a way to center the text vertically? I've tried a couple of things but no success so far... A brute force approach \raisebox{4pt}{...} works, but is, well, brute force.
    – sgmoye
    Jun 27, 2018 at 13:47
  • To clarify: \raisebox{4pt}{...} is for the top row, and \raisebox{-3pt}{...} for the bottom row.
    – sgmoye
    Jun 27, 2018 at 13:54
  • 1
    What about "some text in the right" somewhere? ;-) Jun 27, 2018 at 16:56
  • @sgmoye: See edited answer
    – user2478
    Jun 27, 2018 at 17:25
  • I prefer use two tables, but what's the meaning of |@{} l @{}|@{} c @{}| here? And is it allowed to use two tables with column more than 1, that's why I ask the first question. Jun 28, 2018 at 1:46
10

An alternative to tabular...stacked \frameboxes.

\documentclass{article}
\usepackage{stackengine}
\setstackgap{S}{\fboxrule}
\begin{document}
\Shortstack{%
\framebox(100,30){}
\framebox(100,30){}}%
\Shortstack{%
\framebox(100,20){}
\framebox(100,20){}
\framebox(100,20){}}%
\end{document}

enter image description here

With text:

\documentclass{article}
\usepackage{stackengine}
\setstackgap{S}{\fboxrule}
\begin{document}
\Shortstack{%
\framebox(100,30){left top}
\framebox(100,30){left bottom}}%
\Shortstack{%
\framebox(100,20){right top}
\framebox(100,20){right center}
\framebox(100,20){right bottom}}%
\end{document}

enter image description here

Variable box height. As long as the \framebox heights add to the same number in each column, the top and bottom will be aligned:

\documentclass{article}
\usepackage{stackengine}
\setstackgap{S}{\fboxrule}
\begin{document}
\Shortstack{%
\framebox(100,30){left top}
\framebox(100,30){left bottom}}%
\Shortstack{%
\framebox(100,13){right top}
\framebox(100,30){\stackanchor[4pt]{right}{center}}
\framebox(100,17){right bottom}}%
\end{document}

enter image description here

7

You can actually do it the same way as in Word, by merging cells:

\documentclass{article}
\usepackage{multirow}

\begin{document}

\begin{tabular}{|l|l|}
\hline
\multirow{3}{*}{left 1} & \multirow{2}{*}{right 1} \\
                        &                          \\ \cline{2-2} 
                        & \multirow{2}{*}{right 2} \\ \cline{1-1}
\multirow{3}{*}{left 2} &                          \\ \cline{2-2} 
                        & \multirow{2}{*}{right 3} \\
                        &                          \\ \hline
\end{tabular}

\end{document}

LaTeX output for code above

3
  • That's clever--I hadn't thought of that.
    – sgmoye
    Jun 27, 2018 at 17:05
  • best usage of least common multiple :)
    – Diaa
    Jun 27, 2018 at 22:53
  • I thought about this method before, but here is a problem that, if the case is 5row + 6row, then I need to creare 30row totally. Jun 28, 2018 at 1:41
4

Here's a solution that allows automatic line-breaking in all cells. The solution uses a "outer" tabularx environment (with a total width of your choice; below, the total width is set to \textwidth) with two columns, and two "inner" side-by-side tabular environments with one column each. There can be any number of logical "rows" in each of the two inner tabular environments.

enter image description here

\documentclass[]{article}
\usepackage{tabularx}
\usepackage{ragged2e} % for "\RaggedRight" macro

%% filler text
\newcommand\blurbA{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna.}
\newcommand\blurbB{Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et, tellus.}
\newcommand\blurbC{Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In hac habitasse platea dictumst. Integer tempus convallis augue. Etiam facilisis. Nunc elementum fermentum wisi. Aenean placerat.}

\setlength\extrarowheight{2pt} % for a more open "look"
\newcolumntype{P}[1]%
  {>{\RaggedRight\arraybackslash}p{\dimexpr#1-2\tabcolsep\relax}}

\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|@{}X@{}|@{}X@{}|}
\hline
%% left-hand column
\begin{tabular}[t]{P{\hsize}}
\blurbA\\ \hline
\blurbC % optional: \\ \hline
\end{tabular} &
%% right-hand column
\begin{tabular}[t]{P{\hsize}}
\blurbB\\ \hline
\blurbA\\ \hline
\blurbB
\end{tabular} \\
\hline
\end{tabularx}
\end{document} 
3

I would not for an instant claim that this is the most elegant solution to this problem. Further, using TikZ to accomplish this seems a bit like using a sledge hammer to crack a peanut. It is, however, visually neat and clean, and is easily altered to suit. Suggestions for improvement, as usual, are welcome...

\documentclass{article}

\usepackage{tikz}

%% Any number of rows might be accomodated, you just have to set 'minimum height' accordingly
\tikzset{
    tworow/.style={%
        draw,
        minimum height=3\baselineskip,
        text width=0.5\textwidth-8pt, % 8pt is 2*inner sep + 2*line width (about)
        align=left
        },
    threerow/.style={
        draw,
        minimum height=2\baselineskip,
        text width=0.5\textwidth-8pt,
        align=left
    }
}

\newcommand{\twothreetable}[5]{
\noindent
\begin{tikzpicture}[outer sep=0.0pt,line width=1pt]% Alter 'line width' to suit
    \node (B)[tworow,anchor=south west] {#1};
    \node (C)[tworow,anchor=north west] {#2};
    %
    \node (D)[threerow,anchor=north west] at (B.north east) {#3};
    \node (E)[threerow,anchor=north west] at (D.south west) {#4};
    \node[threerow,anchor=north west] at (E.south west) {#5};
\end{tikzpicture}%
}

\begin{document}

\twothreetable{Text 1 and a bit to indicate what happens with a lot of text}
{Text 2}
{Text 3}
{Text 4}
{Text 5}

\end{document}

enter image description here

1
  • No, I think using TiKZ her is way more appropriate than the other solutions: this is a chart, not a table (or rather, it would be an acceptable chart rather than a poor table). Jun 27, 2018 at 16:59
1

With tcbposter (from tcolorbox) you can construct all kind of complex box distributions.

\documentclass{article}
\usepackage[most]{tcolorbox}

\begin{document}
\begin{tcbposter}[
    poster={columns=2,rows=3, height=3cm,spacing=-.5mm},
    boxes={colframe=black, colback=white, sharp corners, notitle, valign=center}
    ]
    \posterbox{name=11,column=1,row=1,rowspan=1.5}{First box}
    \posterbox{column=1,below=11,rowspan=1.5}{Second box}
    \posterbox{column=2,row=1}{Second column, first row}
    \posterbox{column=2,row=2}{Second column, second row}
    \posterbox{column=2,row=3}{Second column, third row}
\end{tcbposter} 

\begin{tcbposter}[
    poster={columns=2,rows=4, height=5cm, width=.8\textwidth,spacing=-.5mm},
    boxes={colframe=black, colback=white, sharp corners, notitle, valign=center, halign=center}
    ]

\posterbox[colback=green!20, fontupper=\large]
{row=1,column=1,span=2}{Nice title} 

\posterbox[colback=red!70!blue!30]{name=A,column=1,row=2,rowspan=1.2}{A}

\posterbox[colback=red!30!blue!70,valign=bottom, halign=right]{column=1,between=A and bottom}{B}

\posterbox[colback=red!30]{name=C,column=2,row=2,rowspan=0.6}{C}

\posterbox[colback=red!30!cyan!80]{name=E,column=2, above=bottom, rowspan=1.2}{E}

\posterbox[colback=red!80!cyan!30,halign=left]{column=2,between=C and E}{D}
\end{tcbposter} 
\end{document}

enter image description here

You must log in to answer this question.

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