1

How can I create such a table in LaTeX?

enter image description here

I have tried the following:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tabularx,caption,booktabs}

\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

\begin{figure}[htbp]
\captionsetup{justification=raggedright, margin=1cm}
\begin{tabular}{|L{4cm}C{2cm}|L{4cm}C{2cm}|}
\midrule
\textbf{Aktiva} & in \% der Bilanzsumme & \textbf{Passiva} & in \% der Bilanzsumme \tabularnewline
\midrule
Immaterielle Vermögensgegenstände & 1,98 \% & Eigenkapital (einschließlich Rücklagen, Gewinnvortrag, anteiliger Sonderposten mit Rücklageanteil; abzüglich Berichtigungsposten zum Eigenkapital) & 29,87 \\
Sachanlagen & 23,40 & Rückstellungen (einschließlich anteiliger Sonderposten mit Rücklageanteil) & 16,89 \\
\end{tabular}
\end{figure}

\end{document}

enter image description here

My problem is that I do not know how to format the table so that the two columns on the left side are independent from the two columns on the right side. In other words, I want to have the line with "Sachanlagen" directly below "Immaterielle Vermögensgegenstände".

Thanks to all of you in advance!

4
  • The code of the table is almost trivial, but I guess no one is too excited about the prospect of punching in the text. If you provide us with the text, I am pretty sure someone will make it a table.
    – user121799
    Mar 9, 2018 at 15:11
  • Well, it does not have to be that particular text. I would be happy with some exemplary code which makes it clear how to create such a table
    – Andy
    Mar 9, 2018 at 15:22
  • not clear what is the problem .. but try \begin{tabular}{p{4cm} r p{4cm}r} ... & ... & ... & ... \end{tabular}. for more, you should show us, what you tray so far. note, there are more sophisticated solutions which gives more net result.
    – Zarko
    Mar 9, 2018 at 15:28
  • I apologize for my above comment, I misinterpreted your question, and hope that my answer below does what you want to achieve. BTW, why didn't you accept @AlanMunn's answer when you say it works perfectly?
    – user121799
    Mar 9, 2018 at 16:23

2 Answers 2

2

an alternative to nice marmot answer. with similar idea how to make two independent columns pair (with nested tables), however with use of tabularx, siunitx and ragged2e packages.

edit: with defining new environment for nested tables as

\newenvironment{intab}
{
\tabularx{\linewidth}[t]{L|S[table-format=3.2,
                             table-column-width=8ex]}
}
{
\endtabularx
}

the complete table code become shorter and simpler:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{siunitx}
\usepackage{ragged2e}
\usepackage{makecell, tabularx}
\renewcommand\theadfont{\footnotesize\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\RaggedRight}X}
\usepackage[skip=1ex]{caption}

\newenvironment{intab}
{
\tabularx{\linewidth}[t]{L|S[table-format=3.2,
                             table-column-width=8ex]}
}
{
\endtabularx
}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[htbp]
\renewcommand\arraystretch{1.5}
\small
\begin{tabular*}{\linewidth}{|@{}*{2}{p{\dimexpr0.5\linewidth-\arrayrulewidth\relax}@{}|@{}}
                              @{}}
    \Xhline{1pt}
\begin{intab}
\thead[tl]{Aktiva}                  & {\makecell[tl]{in \% der\\ Bilanz-\\summe}}  \\
\end{intab}
    &   \begin{intab}
\thead[tl]{Passiva}                 & {\makecell[t]{in \% der\\ Bilanz- \\summe}}  \\
        \end{intab}  \tabularnewline
    \Xhline{0.5pt}
\begin{intab}
Immaterielle Vermögensgegenstände   & 1,98                                          \\
Sachanlagen                         & 23,40                                         \\
    \rule{0pt}{5.5\baselineskip}    &   \\
\end{intab}
    &   \begin{intab}
Eigenkapital (einschließlich Rücklagen, Gewinnvortrag, anteiliger Sonderposten mit Rücklageanteil; abzüglich Berichtigungsposten zum Eigenkapital)
                                    & 29,87                                         \\
Rückstellungen (einschließlich anteiliger Sonderposten mit Rücklageanteil)
                                    & 16,89                                         \\
        \end{intab}  \tabularnewline
    \hline
    \hline
\begin{intab}
Bilanzsumme                         & 100,00                                        \\
\end{intab}
    &   \begin{intab}
Bilanzsumme                         & 100,00                                        \\
        \end{intab}  \tabularnewline
    \Xhline{1pt}
\end{tabular*}
    \end{table}
\end{document}

enter image description here

3
  • Nice! +1. No more hibernation?
    – user121799
    Mar 10, 2018 at 0:17
  • @marmot, thank you. no more hibernation :-), so in edited answer i make mwe code slightly shorter.
    – Zarko
    Mar 10, 2018 at 0:59
  • I see. You seem to have a better text editor. Mine starts to hibernate when I punch in umlaute (ä, ü, ö, ß etc.) :-(
    – user121799
    Mar 10, 2018 at 2:24
2

OK, I misinterpreted your question. To make the left and right rows independent, just make them two separate tables. I also included dcolumns in order to make sure that the numbers get aligned at the commas (and used b type columns such that the numbers are aligned with the bottoms of long texts).

\documentclass{article}
\usepackage{dcolumn}
\usepackage{tabularx}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\newcolumntype{,}{D{,}{,}{2}}
\centerline{
\begin{tabular}{|@{}b{7.9cm}|@{}b{7.9cm}|}
\hline
\begin{tabular}{b{5.75cm}|,}
\textbf{Aktiva} & \multicolumn{1}{p{1.5cm}}{in \%\ der Bilanzsumme} \\ 
\hline
text & 1,00 \\
some very long text with a lot of items and explanations and references to ducks
& 4,20  \\
\end{tabular}& 
\begin{tabular}{b{5.75cm}|,}
\textbf{Aktiva} & \multicolumn{1}{p{1.5cm}}{in \%\ der Bilanzsumme} \\ 
\hline
text & 1,30 \\
text
& 2,20  \\ \\ \\
\end{tabular}\\
\hline
\hline
\begin{tabular}{b{5.75cm}|,}
Bilanzsumme & \multicolumn{1}{p{1.5cm}}{\raggedleft 100,00} \\
\end{tabular}&
\begin{tabular}{b{5.75cm}|,}
Bilanzsumme & \multicolumn{1}{p{1.5cm}}{\raggedleft 100,00} \\
\end{tabular}\\
\hline
\end{tabular}}
\end{document}

enter image description here

10
  • Quite nice given the difficulty of the problem. A drawback is the necessity of adding series of \\. I am missing something that would adjust the height of the two tables without having to do this.
    – Denis
    Mar 9, 2018 at 16:37
  • @Denis Sure, there might be a hack that allows one to avoid this. But I would like to argue that finding and implementing the hack is probably not worth the effort, and may also have other side effects.
    – user121799
    Mar 9, 2018 at 16:46
  • I agree. I would nevertheless be glad to study the hack, which I am unable to devise :-(
    – Denis
    Mar 9, 2018 at 17:00
  • i wonder why one should compose one table from two independent tables and struggles then with aligning rows height. strange. very strange .... something in the sense: why something could be done simply, if I can do the same in a much more complicated way :-)
    – Zarko
    Mar 9, 2018 at 17:06
  • @Zarko Did you read the question? The OP wants the left two rows independent from the right two rows. If you have a simpler solution, please go ahead.
    – user121799
    Mar 9, 2018 at 17:08

You must log in to answer this question.

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