3

I am trying to fit a rather large table to my page. It is to wide for the page. I tried something like

\begin{longtable}{| p{0.14\textwidth} | p{0.14\textwidth} | 
p{0.14\textwidth} | p{0.14\textwidth} | p{0.14\textwidth} | 
p{0.14\textwidth} | p{0.14\textwidth} |}

because I have seven columns.

One of the problems I now have is that, as I'm using scrartcl, the annotation space is included into \textwidth too, but of course I want to stay inside the normal limits.

Also, I am already using footnotesize, but it does not separate words --> if they are too long, they are partially written in the next column.

I now need a method, that fits the table into the "normal" page width (as shown by showframe) and also adds a linebreak or separates words, in order to avoid writing into the next column.

I didn't post a minimal example, because I'm open to every possible solution, (but it should use something like longtable and, if possible, adjust the column size in relation to the \textwidth).
(sorry if this looks a bit messy)

\begin{footnotesize}
\begin{center}
  \begin{longtable}{| p{0.14\textwidth} | p{0.14\textwidth} |
  p{0.14\textwidth} | p{0.14\textwidth} | p{0.14\textwidth} | 
  p{0.14\textwidth} | p{0.14\textwidth} |}
    \hline 
  \textbf{Variable} & \textbf{Kurzbezeichnung} & \textbf{Frage} & \textbf{type} & \textbf{value label} & \textbf{Range} & \textbf{missing value}\\
  \hline
  \endhead % all the lines above this will be repeated on every page
  ffhrwoggbgbgfieh & fefgogergeroigregb & fhoergregre & fhoerghergie & herogheggire & hgieghrgri & ngjreoigehrero\\
  \hline
  \caption{Alle Variablen von der Dokumentation aus dem Codebuch.}
  \label{tab:VarDoku}
  \end{longtable}
\end{center}
\end{footnotesize}
7
  • Welcome to TeX.SE. Can you add the complete code. Thus we can help you.
    – Sebastiano
    Jan 31 '17 at 9:55
  • There are 2 ways of formatting code -- for long blocks indenting by 4 spaces (or highlight and press the {} button on the full website) looks better than backticks. An image would help, as there are a few ideas, some but not all of which would work in any particular situation. If you're on the desktop version of the website, the "related" links to the right might be helpful
    – Chris H
    Jan 31 '17 at 10:15
  • You're writing in German by the look of things. I don;t know how hyphenation patterns are handled in compound words in German, but I would guess that for long uncommon compounds you need to specify that patterns at the start of your document for example \hyphenation{electro-reflect-ance thermo-reflect-ance electro-lumin-escence}
    – Chris H
    Jan 31 '17 at 10:19
  • @ChriSH: thank you for editing, it is not only this table, I have several tables in my document, all of them a bit different, so it should be an example that works for all kinds of large tables, if possible.
    – LizzAlice
    Jan 31 '17 at 10:24
  • Isn't there a command that automatizes german hyphenation? As it is a large document, I can't possibly specify all of it.
    – LizzAlice
    Jan 31 '17 at 10:26
3

There's no way “Kurzbezeichnung” can be accommodated in such a narrow width, so I abbreviated it into ”KB”.

\documentclass{article}
\usepackage{longtable,calc,array}

\newlength\alicewidth

\begin{document}

\begingroup\footnotesize
\setlength{\alicewidth}{\textwidth/7-2\tabcolsep-8\arrayrulewidth/7}
\begin{longtable}{|*{7}{>{\raggedright\arraybackslash}p{\alicewidth}|}}
\hline
\textbf{Variable} & \textbf{KB} & \textbf{Frage} &
  \textbf{type} & \textbf{value label} & \textbf{Range} & \textbf{missing value}\\
\hline
\endhead % all the lines above this will be repeated on every page

ffhrwo ggbgbg fieh & fefgo gerge roigr egb & fhoerg regre & fhoerg hergie &
 herogh eggire & hgieg hrgri & ngjreoi gehrero\\

\hline
\caption{Alle Variablen von der Dokumentation aus dem Codebuch.\label{tab:VarDoku}}
\end{longtable}
\endgroup

\end{document}

enter image description here

2
  • Great, that did nearly all I wanted, I still have problems with some words that are to long for the column, do I have to specify these with \hyphenation then?
    – LizzAlice
    Jan 31 '17 at 10:40
  • @LizzAlice - You could provide the instruction \hyphenation{kurz-be-zeich-nung} in the preamble and write the cell as \hspace{0pt}\textbf{Kurzbezeichnung}. (The \hspace{0pt} directive serves to enable hyphenation of the subsequent word.)
    – Mico
    Jan 31 '17 at 10:54
0

I'd use the ltablex package, which combines the functionalities of longtable and tabularx, and makecell to have a common formatting of all column heads. Also, table captions usually are placed above table, especially in the case of multipage tables, for the reader's ease:

\documentclass[a4paper]{scrartcl}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{caption, ltablex, makecell}%
\captionsetup{font=footnotesize, labelfont=sc}
\renewcommand\theadfont{\footnotesize\bfseries}
\usepackage{showframe} %
\renewcommand\ShowFrameLinethickness{0.3pt}
\renewcommand{\tabularxcolumn}[1]{>{\footnotesize\arraybackslash}p{#1}}

\begin{document}

\
\keepXColumns
\begin{tabularx}{\linewidth}{|*{7}{ X|}}
  \caption{Alle Variablen von der Dokumentation aus dem Codebuch.}\medskip
  \label{tab:VarDoku}\\
  \hline \thead{Variable} & \thead{Kurzbe- & & & & & \\zeichnung} & \thead{Frage} & \thead{Type} & \thead{Value\\ label} & \thead{Range} & \thead{Missing\\ value}\\
  \hline
  \endfirsthead
  \hline
  \thead{Variable} & \thead{Kurzbe- & & & & & \\zeichnung} & \thead{Frage} & \thead{type} & \thead{value\\ label} & \thead{Range} & \thead{missing\\ value}\\
  \hline
  \endhead % all the lines above this will be repeated on every page
  ffhrwogg bgbgfieh & fefgogerge roigregb & fhoergregre & fhoerghergie & herogheggire & hgieghrgri & ngjreoigeh rero \\

  \hline
\end{tabularx}

\end{document} 

enter image description here

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.