Graphics, Figures & TablesTable formatting

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
zwep
Posts: 2
Joined: Tue Nov 17, 2015 4:30 pm

Table formatting

Post by zwep »

Hello,

In the attachment is my output table, where some text is made black as you can see.
But I do not like the formatting of it, I want all the tables to look like the format of 'Code 06'... But I can't seem to get it right.
The code used to generate these tables is by using the following command:

Code: Select all

\newcommand{\Tabel}[9]{
\begin{tabular}{l|p{2.4cm}p{2.4cm}p{2.4cm}|p{8cm}} \hline
\isText{#1}{Code}   & \isText{#2}{\textbf{P}ercentage \textbf{1}} & \isText{#4}{\textbf{M}in. perc. \textbf{1}} & \isText{#6}{\textbf{G}rensbedrag}   & \multirow{4}{*}{#8}\\
 \isEmpty{#1}       & \isLine{#2}               & \isLine{#4}               & \isLine{#6}                   &  \\
                    & \isText{#3}{\textbf{P}ercentage \textbf{2}} & \isText{#5}{\textbf{M}in. perc. \textbf{2}} & \isText{#7}{\textbf{B}ovengrens}       &  \\
                    & \isLine{#3}               & \isLine{#5}               & \isLine{#7}                   &  \\ [{#9}]
\end{tabular}}

Where the following additional 'functions'  are used to trigger the appearance of some text.

\newcommand{\isEmpty}[1]{\ifthenelse{\equal{#1}{}}
{}{{#1}}}
\newcommand{\isLine}[1]{\centering \ifthenelse{\equal{#1}{}}
{}{{ $\ldots$}}}
\newcommand{\isText}[2]{\ifthenelse{\equal{#1}{}}
{}{{#2}}}

This table is then called with the following command

\Tabel{06}{@}{@}{@}{@}{@}{}{
\begin{tabular}{lp{4cm}}
\Bound{0}{G}: & P1 \PL XXXX XXXX XXXX XXXX\\ 
                                \Bound{G}{HS}: & P2 \PL XXXXXX XXXXXX.\\ \It{Optioneel}: & M1, M2
\end{tabular}
}
{2ex}
The '@' is used to trigger the appearance of one of the table variable names (like Percentage, or Grensbedrag)

The difficulty lies in the usage of \multirow in combination with the table inside it. I've tried to use some bounding boxes as well, but this didn't gave me the desired result.
What I want is the following structure

Code: Select all

Code__|_'Options'____________|_Description______________ |
textte|texttexttexttexttextte| van..tot:.................|
.........................................................
textte|texttexttexttexttextte| van..tot:.................|
.........................................................
textte|texttexttexttexttextte|Optioneel:.................|
______|______________________|___________________________|
(sorry about this bad ASCII formatting.. in the editor it looked a lot better)

where it is important that the 'dotted' rows are variable. Such that the height of the table is proportional to the length of the description.
My question is: do you guys know more ways to configure the size/height/formatting of/inside tables? Because I'm kind of stuck in my current options and find it hard to find new solutions.
Attachments
table.png
table.png (30.54 KiB) Viewed 5373 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table formatting

Post by Johannes_B »

Welcome,

the code you posted does not compile. Some things i was able to guess, but some things are completely unknown to me. Can you please provide a minimal working example?


Is this for automation of big data several times? Or is this in one document with only a few instances?

I am also not sure, what the multirow is currently doing. Most tables that use multirow don't need it or would look better without it.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
zwep
Posts: 2
Joined: Tue Nov 17, 2015 4:30 pm

Table formatting

Post by zwep »

Hello John,

sorry for my late reply. I see now that I forgot to add some definition and packages.. The code below is running for me (in Sharelatex)

Code: Select all

\documentclass{article}

\usepackage{ifthen}
\usepackage{multirow}
\usepackage[margin=0.5in]{geometry}

\newcommand{\Bound}[2]{\textbf{Van {#1} tot {#2}}}
\newcommand{\PL}{$+ \ $}
\newcommand{\MI}{$- \ $}
\newcommand{\It}[1]{\textit{#1}}

\newcommand{\isEmpty}[1]{\ifthenelse{\equal{#1}{}}
{}{{#1}}}
\newcommand{\isLine}[1]{\centering \ifthenelse{\equal{#1}{}}
{}{{ $\ldots$}}}
\newcommand{\isText}[2]{\ifthenelse{\equal{#1}{}}
{}{{#2}}}

\newcommand{\Tabel}[9]{
\begin{tabular}{l|p{2.4cm}p{2.4cm}p{2.4cm}|p{8cm}} \hline
\isText{#1}{Code}   & \isText{#2}{\textbf{P}ercentage \textbf{1}} & \isText{#4}{\textbf{M}in. perc. \textbf{1}} & \isText{#6}{\textbf{G}rensbedrag}   & \multirow{4}{*}{#8}\\
 \isEmpty{#1}       & \isLine{#2}               & \isLine{#4}               & \isLine{#6}                   &  \\
                    & \isText{#3}{\textbf{P}ercentage \textbf{2}} & \isText{#5}{\textbf{M}in. perc. \textbf{2}} & \isText{#7}{\textbf{B}ovengrens}       &  \\
                    & \isLine{#3}               & \isLine{#5}               & \isLine{#7}                   &  \\ [{#9}]
\end{tabular}}




%Where the following additional 'functions'  are used to trigger the appearance of some text.



%This table is then called with the following command

\begin{document}

\Tabel{06}{@}{@}{@}{@}{@}{}{
\begin{tabular}{lp{4cm}}
\Bound{0}{G}: & P1 \PL XXXX XXXX XXXX XXXX\\ 
                                \Bound{G}{HS}: & P2 \PL XXXXXX XXXXXX.\\ \It{Optioneel}: & M1, M2
\end{tabular}
}
{2ex}

\end{document}

I use multiple instances of this definition of \Tabel in the document (around 100 times). This collection of tables used to be made in Word, but I didn't like the formatting and typeset, so I wanted to make it more rigorous with LaTeX. :)
Last edited by Stefan Kottwitz on Fri Nov 20, 2015 12:34 pm, edited 1 time in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table formatting

Post by Johannes_B »

I have to admit, that i am a little bit lost with your example and don't understand fully how it is supposed to work.

I think each Tabel is one line of a bigger table, and the percentage things are subentries in that one line. If so, the logic is messed up. You should have a tabular inside the tabular for those subentries, not for the bigger entry.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
rais
Posts: 419
Joined: Sun Nov 16, 2014 8:51 pm

Table formatting

Post by rais »

Here's an idea without multirow, even though I'm a bit confused, too, whatever this \Tabel really should do...
You might want to add some proper comments to your code, which
parameter is supposed to be what. Two or three parameters may be OK to remember, but nine?
What's more, I've split your original eigths argument into five, so this version of \Tabel requires a total of thirteen parameters...

Code: Select all

\documentclass{article}

\usepackage{ifthen}
\usepackage{array}
\usepackage[margin=0.5in]{geometry}

\newcommand{\Bound}[2]{\textbf{Van {#1} tot {#2}}}
\newcommand{\PL}{$+ \ $}
\newcommand{\MI}{$- \ $}
\newcommand{\It}[1]{\textit{#1}}

\newcommand{\isEmpty}[1]{\ifthenelse{\equal{#1}{}}
{}{{#1}}}% (rais) why bother?

% (rais) if \isLine is called in the last tabular column,
% its \centerline would unhinge the tabular's \\
% see also `texdoc array'
\newcommand{\isLine}[1]{\centering\arraybackslash% <--
  \ifthenelse{\equal{#1}{}}
{}{{ $\ldots$}}}
\newcommand{\isText}[2]{\ifthenelse{\equal{#1}{}}
{}{{#2}}}

% (rais) the following 4 calls to \newcommand are just
% supposed to throw an error message in case some package
% author had the same idea for naming one of those macros,
% as I did. The real definition for those macros is done
% in the (new) \Tabel definition.
\newcommand*\TabArgI{}
\newcommand*\TabArgII{}
\newcommand*\TabArgIII{}
\newcommand*\TabArgIV{}

\newcommand\Tabel[4]{% (rais) \Tabel now effectively expects
% 13 arguments: note the call to \TabelI here without parameters
  \edef\TabArgI{#1}%
  \edef\TabArgII{#2}%
  \edef\TabArgIII{#3}%
  \edef\TabArgIV{#4}%
  \TabelI
}
\newcommand\TabelI[9]{% (rais) not to be called directly!
  \begin{tabular}{l|c|r}% outer tabular
    \hline
    % 1st inner tabular:
    \begin{tabular}[t]{@{}l@{}}
      \isText{\TabArgI}{Code}\\
      \TabArgI
    \end{tabular} &
    % 2nd inner tabular:
    \begin{tabular}[t]{@{}p{2.4cm}p{2.4cm}p{2.4cm}@{}}
      \isText{\TabArgII}{\textbf{P}ercentage \textbf{1}}
      & \isText{\TabArgIV}{\textbf{M}in. perc. \textbf{1}}
      & \isText{#2}{\textbf{G}rensbedrag}\\
      \isLine{\TabArgII}
      & \isLine{\TabArgIV}
      & \isLine{#2}\\
      \isText{\TabArgIII}{\textbf{P}ercentage \textbf{2}}
      & \isText{#1}{\textbf{M}in. perc. \textbf{2}}
      & \isText{#3}{\textbf{B}ovengrens}\\
      \isLine{\TabArgIII}
      & \isLine{#1}
      & \isLine{#3}
    \end{tabular} &
    % 3rd inner tabular:
    \begin{tabular}[t]{@{}% no additional space left of inner tabular
        p{\dimexpr 3cm-2\tabcolsep\relax}% to match the 8cm for both columns
        >{\raggedright\arraybackslash}p{5cm}% fixed width column with its
        % contents flush left; for more info on the `>{..}' modifier, see
        % `texdoc array'
        @{}% no additional space right of inner tabular
        }
      \ifx\relax#4#5\relax% if arguments 8 and 9 (to \Tabel) are empty,
        % skip whole line
      \else
        \isText{#4}{#4:} & #5\\
      \fi
      \ifx\relax#6#7\relax\else
        \isText{#6}{#6:} & #7\\
      \fi
      \ifx\relax#8\relax\else
        \textit{Optioneel}: & #8
      \fi
    \end{tabular}\\[#9]
  \end{tabular}
}

% (rais) the following ensures a little free space between a
% capital letter and a line above it within a tabular,
% see also `texdoc array'
\setlength\extrarowheight{1pt}

\begin{document}
\Tabel{06}{@}{@}{@}{@}{@}{}
  {\Bound{0}{G}}{P1 \PL XXXX XXX XX X X XXX XX}
  {\Bound{G}{HS}}{P2 \PL XXXXXX XXXXXX.}
  {M1, M2}
  {2ex}

\Tabel{07}{@}{@}{@}{@}{@}{}
  {\Bound{0}{G}}{P1 \PL XXXX XXX XX X X XXX XX}
  {}{}
  {Mx}
  {2ex}
\end{document}
But perhaps you're just looking for tabularx and its X-column.

KR
Rainer
Post Reply