1

I have tried a few different solutions for automatic line breaks within tables in LaTeX. Below is an example of a tabular list using my most elaborate method so far. It looks alright in PDF, but it still throws several warnings. One or two entries may still be so long that they're escaping the specified text width, which means that line breaks aren't working as intended. How can I get proper and reliable automatic line breaks within tables in LaTeX?

\begin{center}
\begin{tabular*}{\columnwidth}{ @{\extracolsep{\fill}} p{0.5\columnwidth}p{0.5\columnwidth}}
Matrikel-Nr:  & 1234567\\
E-Mail:  & xxxxxxxx.xxxxxxxx@xxx-xxxxxxxxx.xx\\
 & \\
{\bf Seminar} & {\bf Dozent:in}\\
123456 Einführung in die Statistik mit R & Dr. Xxxxxx Xxxxxxxxx\\
123456 Einführung experimentelle Methoden & Dr. Xxxxxx Xxxxxxxxx\\
123456 Aufbaukurs quan\-ti\-ta\-ti\-ve Methoden & Dr. Xxxxxx Xx\-xxxx\-xxxxxxx\\
 & \\
Xxxxxxxxx, \today & \\
\end{tabular*}
\end{center}

The warnings I get when compiling this are the following:

Underfull \hbox (badness 10000) in paragraph at lines 66--67
Underfull \hbox (badness 1122) in paragraph at lines 69--69
Underfull \hbox (badness 2582) in paragraph at lines 70--70
Overfull \hbox (17.99998pt too wide) in alignment at lines 64--74

(The segment above corresponds to lines 63--75 in my file)

Preamble:

\documentclass[twoside,openright,12pt]{report}

\usepackage{latexsym}
\usepackage[dvips]{graphics}
\usepackage{pgf}
\usepackage{multicol}
\usepackage[german]{babel}
\usepackage{linguex}
\usepackage{hyperref}
\usepackage{fontspec}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{array}
\usepackage{multirow}
\usepackage{makecell}
\setmainfont[BoldFont={Gentium Basic Bold},ItalicFont={Gentium Plus Italic}, BoldItalicFont={Gentium Basic Bold Italic}]{Gentium Plus}
\usepackage[scaled]{helvet}
\usepackage{apacite}
\usepackage{fancyhdr}

% set up page size. 
\sloppy
\setlength{\textwidth}{15cm}
\setlength{\oddsidemargin}{42pt}
\setlength{\evensidemargin}{-22pt}
\setlength{\headheight}{15pt}
3
  • Welcome to TeX.SX! Unrelated to the issue, but you might want to replace \bf with \bfseries. For some background information, see also: “Correct” way to bold/italicize text? – leandriis Feb 19 at 18:16
  • 1
    Regarding the issue itself, \begin{tabular}{@{}p{\dimexpr 0.5\linewidth-\tabcolsep}p{\dimexpr 0.5\linewidth-\tabcolsep}@{}} or \begin{tabularx}{\linewidth}{@{}XX@{}}(needs the tabularx package) should work without warnings. – leandriis Feb 19 at 18:19
  • 2
    it is much easier to answer if you post a test document not two disconnected fragments and also if you remove every package not used in the example. (also if you can demonstrate the problem with a standard font. – David Carlisle Feb 19 at 20:24
0

To get "automatic line breaks" in table entries, you'd need to use the p{some-width-here} (paragraph) column specification.

2
  • 1
    The code in the question already uses p columns. – campa Feb 19 at 23:17
  • Come on, people, the downvote was really unnecessary. – campa Feb 20 at 15:49
0

Try to use tabularx, which is already loaded in your preamble. It will calculate itsel corect width of columns, so you will not receive warnigs about Underfull \hbox ...:

\documentclass[twoside,openright,12pt]{report}
\usepackage{geometry}
\usepackage{fontspec}
\setmainfont[BoldFont={Gentium Basic Bold},
             ItalicFont={Gentium Plus Italic},
             BoldItalicFont={Gentium Basic Bold Italic}%
             ]{Gentium Plus}
\usepackage[scaled=0.92]{helvet}
\usepackage{lipsum}
% tables
\usepackage{array, booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{hyperref} % had to be loaded last

\begin{document}
\lipsum[1]
    \begin{center}
\begin{tabularx}{\linewidth}{ @{} LL @{}}
Matrikel-Nr:        & 1234567                           \\
E-Mail:             & xxxxxxxx.xxxxxxxx@xxx-xxxxxxxxx.xx\\
    \addlinespace
\textbf{Seminar}    & \textbf{Dozent: in}               \\
123456 Einführung in die Statistik mit R 
                    & Dr. Xxxxxx Xxxxxxxxx              \\
123456 Einführung experimentelle Methoden 
                    & Dr. Xxxxxx Xxxxxxxxx              \\
123456 Aufbaukurs quan\-ti\-ta\-ti\-ve Methoden 
                    & Dr. Xxxxxx Xx\-xxxx\-xxxxxxx      \\
    \addlinespace
Xxxxxxxxx, \today   & \\
\end{tabularx}
    \end{center}
\lipsum[2]
\end{document} 

enter image description here

Cause of your problems is already explained in @leandriis comment. Off-topic: package hyperref had to be (with rare exception) loaded last in preamble.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.