1

I am trying to make table with text (this is for a medieval roleplaying).

\begin{tabular}{ l l l l }
Delikt & Leichte Strafe & Mittlere Strafe & Schwere Strafe \\
Angriff auf einen Geweihten & Brandzeichnung & Blendung oder Abschneiden von Zungen oder Hand & Tod \\
Anstiftung zu Aufruhr &  Brandzeichnung & Tod &  Tod durch Rädern \\
Aufwiegelung & Bis zu 10 Stockhiebe & Pranger & Verbannung \\
\end{tabular}

Thank you very much in advance.

How can I create equal columns? In MS Word, columns can be adjusted so that they are all the same width, but is this possible with LaTeX as well?

4
  • Welcome to TeX SX! Use the tabularx environment and the X column type. If it has to be more than one page long, use xltabular instead, so that it can break across pages.
    – Bernard
    Commented May 29, 2022 at 21:38
  • Could you please give me an example? Thank you in advance. Commented May 29, 2022 at 21:40
  • It's very simple: the table preamble is \begin{tabularx}{\textwidth}{XXXX} to have 4 equal columns.
    – Bernard
    Commented May 30, 2022 at 6:45
  • Thank you very much! Commented May 30, 2022 at 12:33

2 Answers 2

1

You can prescribe column widths with p (or m and b) columns type. For example, you can write your table as:

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}
\centering
\begin{tabular}{ *{4}{>{\raggedright\arraybackslash}p{9em}} }
Delikt  & Leichte Strafe & Mittlere Strafe & Schwere Strafe \\
Angriff auf einen Geweihten 
        & Brandzeichnung 
            & Blendung oder Abschneiden von Zungen oder Hand 
                & Tod \\
Anstiftung zu Aufruhr 
        &  Brandzeichnung 
            & Tod 
                &  Tod durch Rädern \\
Aufwiegelung 
        & Bis zu 10 Stockhiebe 
            & Pranger 
                & Verbannung \\
\end{tabular}
\end{document}

which gives

enter image description here

As you can see, in this cases long text in cells are broken into more lines.

original answer However, see, if use of the tabularray package with library siunitx gives acceptable (nicer) result:

\documentclass{article}
\usepackage[skip=0.333\baselineskip,
            font=small, labelfont=bf]{caption}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table}[ht]
    \centering
    \caption{Vertical and lateral stresses of mortar.}
    \label{tab:c}
\begin{tblr}{hlines, vlines,
             colspec = {Q[l, wd=5em] *{3}{Q[c, wd=5em, si={table-format=1.2}]}},
              row{1} = {font=\bfseries}
             }
        & {{{Item 1}}} 
                & {{{Item 2}}} 
                    & {{{Item 3}}}  \\  
Group1  & 0.8   & 0.1   & 0.1       \\
Group2  & 0.1   & 0.8   & 0.1       \\
Group3  & 0.1   & 0.1   & 0.8       \\
Group4  & 0.34  & 0.33  & 0.33      \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

Edit: Ups, I wrongly replicate table from answer of @WinnieNotThePooh. Well, it may serv as skeleton for a some similar table with numbers which you like to align at their decimal points.

With your table, which fragment you show in question, a possible solution using tabularray package, can be:

\documentclass{article}
\usepackage{geometry}
\usepackage[ngerman]{babel}
\usepackage{ragged2e}
\usepackage[skip=0.333\baselineskip,
            font=small, labelfont=bf]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
    \begin{table}[ht]
    \centering
    \caption{Vertical and lateral stresses of mortar.}
    \label{tab:c}
\begin{tblr}{ colsep = 3pt,
             colspec = {@{} *{4}{X[cmd=\RaggedRight]} @{}},
              row{1} = {font=\small\bfseries}
             }
    \toprule
Delikt  & Leichte Strafe 
                & Mittlere Strafe 
                        & Schwere Strafe        \\
    \midrule
Angriff auf einen Geweihten
        & Brandzeichnung
                & Blendung oder Abschneiden von Zungen oder Hand
                        & Tod                   \\
Anstiftung zu Aufruhr
        &  Brandzeichnung
                & Tod   &  Tod durch Rädern     \\
Aufwiegelung
        & Bis zu 10 Stockhiebe
                & Pranger
                        & Verbannung            \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

The compilation result is:

enter image description here

Better filling of textyou will get if you will reduce font size in table to \small (by adding this command after \begin{table}). In this case table will looks as follows:

enter image description here

2
  • Thank you very much. One problem though: I get this error: File `tabularray.sty' not found. I am using TexLive2020 and it should be installed. Any idea how to fix this? Commented May 30, 2022 at 6:35
  • @Brayanokles, sorry, but I'm not familiar with TeXlive. Package is relative new (from the end 2020, but recent version is from March this year), so it is possible that is not part of your TeXlive. Try to install it manually. At Jun 1st, will be available new version 2022B.
    – Zarko
    Commented May 30, 2022 at 6:40
0

Taken from here example 4.12

enter image description here

\documentclass{article}    
\usepackage[left=1.5cm,right=1.5cm,top=1.5cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{tabularx}
\begin{document}
\begin{table}[!ht]
\caption{Vertical and lateral stresses of mortar.}
\vspace{0.5cm}
\begin{tabularx}{\textwidth}{|X | X | X | X|}
\hline
& Item1 & Item2 & Item3 \\ \hline
Group1 & 0.8 & 0.1 & 0.1 \\
Group2 & 0.1 & 0.8 & 0.1 \\
Group3 & 0.1 & 0.1 & 0.8 \\
Group4 & 0.34 & 0.33 & 0.33 \\ 
\hline
\end{tabularx}
\label{c}
\end{table}
\end{document}
4
  • Thank you very much! Commented May 29, 2022 at 21:54
  • I would prescribe smaller table width, for example 0.5\textwidth and table centered in the table float environment.
    – Zarko
    Commented May 29, 2022 at 22:09
  • @Brayanokles if it's really helped You, mark it as usefull, please Commented May 29, 2022 at 22:50
  • That's the green thing on the left? Commented May 30, 2022 at 6:17

You must log in to answer this question.

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