# table doesn't fit on page due to width

I have a table that, due to long text, is not fitting on the (landscape) page. consider this code as an example (packages used in the actual document, so included them to avoid compatibility issues):

\documentclass[a4paper,12pt]{article}

\usepackage{natbib}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage{csquotes}
\usepackage[ddmmyyyy]{datetime}
\usepackage{color}
\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{float}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{mathtools}

\begin{document}

\begin{landscape}
\begin{table}[]
\begin{tabular}{@{}|c|c|c|c|c|c|c|c|c|@{}}
\toprule
\textbf{tex1}     &  foo       & text here          & some more, longer text &really long text here that makes table wide&text&longer text&more text& text that is also really long \\ \bottomrule
\end{tabular}
\caption{individuals reactions by actor-specific characteristics}
\label{tab:individuals reactions by actor-specific characteristics}
\end{table}
\end{landscape}

\end{document}


I cannot get other solutions like this one to work that are using p{width} or resizebox which are mentioned elsewhere due to the \begin{tabular}{@{}|c|c|c|c|c|c|c|c|c|@{}}-line in my code.

As I'm rather new to LaTeX, could someone point me to the best solution? Thanks a lot and all the best.

• My table doesn't fit; what are my options? might be interesting – leandriis Sep 24 '19 at 16:59
• Possible duplicate: My table doesn't fit; what are my options? – Werner Sep 24 '19 at 16:59
• The same question was two days ago. Have the search function stopped working? – Sveinung Sep 24 '19 at 19:40
• c, l and r columns cannot break the cells texts, so the column width is fixed by the cell with the longest text. But you can change that columns types by a p column of fixed witdth that allow text wrapping. E.g.: Instead of some like \begin{tabular}{c|r|l} you ca use some like \begin{tabular}{p{3cm}|p{6em}|p{0.25\linewidth}}} – Fran Sep 24 '19 at 22:59

With use of tabularx you can obtain:

\documentclass[a4paper,12pt]{article}

\usepackage{lscape}
\usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}

\begin{landscape}
\begin{table}
\setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{cccCCcccC}
\toprule
\cmidrule(l){1-1}\cmidrule(l){2-3}\cmidrule(l){4-7}\cmidrule(l){8-9}
\textbf{tex1}     &  foo       & text here          & some more, longer text &really long text here that makes table wide&text&longer text&more text& text that is also really long \\ \bottomrule
\end{tabularx}
\caption{individuals reactions by actor-specific characteristics}
\label{tab:individuals reactions by actor-specific characteristics}
\end{table}
\end{landscape}

\end{document}


The solution coming closest to what I wanted is using \newcolumntype{P} and then defining the column widths manually (see below).

\documentclass[a4paper,12pt]{article}

\usepackage{float}
\usepackage{lscape}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}

\begin{table}[H]
\begin{tabular}{|P{2cm}||P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}|P{0.8cm}||}
\hline
\textbf{position} & \multicolumn{2}{P{2cm}|}{text no. one} & \multicolumn{4}{c|}{text}                         & \multicolumn{2}{c|}{text no. two} \\ \hline
\textbf{other} & \multicolumn{2}{c|}{-} & \multicolumn{2}{c|}{towards no. one} & \multicolumn{2}{c|}{away from no. one} & \multicolumn{2}{c|}{-} \\ \hline
\textbf{two line text} & low          & high          & low          & high           & low          & high          & low          & high           \\ \hline
\end{tabular}
\end{table}

\end{document}