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!

Andy
  • 55
  • 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. –  Mar 09 '18 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 09 '18 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 09 '18 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? –  Mar 09 '18 at 16:23

2 Answers2

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

  • 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 09 '18 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. –  Mar 09 '18 at 16:46
  • I agree. I would nevertheless be glad to study the hack, which I am unable to devise :-( – Denis Mar 09 '18 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 09 '18 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. –  Mar 09 '18 at 17:08
  • one table with four columns, as i suggested in my comment. however, comment is on wrong place, it should be below of question :-). your solution is interesting/good :-)) – Zarko Mar 09 '18 at 17:15
  • @Zarko That happens if one does not hibernate enough ;-) –  Mar 09 '18 at 17:23
  • @marmot, you are right. in my places last snow is going away, bears are already weak up ... (marmots we haven't ), so time for hibernation is over. i need to accommodate myself to the this fact :-) :-) :-) – Zarko Mar 09 '18 at 17:26
  • @marmot, now i weak up. op really need more sophisticated table ... (with nested tables). – Zarko Mar 09 '18 at 21:25
  • @marmot, inspired with your solution i wrote a little bit different variant. basic idea is the same. – Zarko Mar 09 '18 at 23:43
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

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