2

I have this table:

\documentclass{scrbook} \usepackage{lipsum}% only for dummy text \usepackage{tabularray} \begin{document} \begin{table} \begin{longtblr}[]{ width = 1\textwidth, cells = {c}, cell{1}{1} = {c=12}{}, cell{2}{1} = {c=6}{}, cell{2}{7} = {c=6}{}, cell{3}{1} = {c=4}{}, cell{3}{5} = {c=4}{}, cell{3}{9} = {c=4}{}, cell{4}{1} = {c=3}{}, cell{4}{4} = {c=3}{}, cell{4}{7} = {c=3}{}, cell{4}{10} = {c=3}{}, cell{5}{1} = {c=2}{}, cell{5}{3} = {c=3}{}, cell{5}{6} = {c=2}{}, cell{5}{8} = {c=3}{}, cell{5}{11} = {c=2}{}, cell{6}{2} = {c=3}{}, cell{6}{5} = {c=2}{}, cell{6}{7} = {c=2}{}, cell{6}{9} = {c=3}{}, hlines, vlines, } 1 & & & & & & & & & & & \\ 2& & & & & & 2 & & & & & \\ 3 & & & & 3 & & & & 3 & & & \\ 4 & & & 4 & & & 4& & &4& & \\ 5 & & 5 & & & 5 & & 5 & & & 5 & \\ 6Loerm Ipsum&6 Lorem Ipsum & & & 6Lorem Ipsum& &6 Lorem Ipsum& & 6Lorem Ipsum& & &6 Lorem Ipsum \end{longtblr} \end{table} \end{document} 

Unfortunately, when I type text into the last column, the table expands beyond the edge of the page. Is there a way to force this table to maintain a width equal to the width of the text?

LaTeX displays: Overfull \hbox (83.53403pt too wide) detected at line 40

After some trails, is it good way?:

 \documentclass{scrbook} \usepackage{tabularray} \begin{table} \begin{longtblr}[]{ rows = {rowsep=1pt}, columns = {colsep=1pt}, cells = {c}, cell{1}{1} = {c=12}{}, cell{2}{1} = {c=6}{}, cell{2}{7} = {c=6}{}, cell{3}{1} = {c=4}{}, cell{3}{5} = {c=4}{}, cell{3}{9} = {c=4}{}, cell{4}{1} = {c=3}{}, cell{4}{4} = {c=3}{}, cell{4}{7} = {c=3}{}, cell{4}{10} = {c=3}{}, cell{5}{1} = {c=2}{}, cell{5}{3} = {c=3}{}, cell{5}{6} = {c=2}{}, cell{5}{8} = {c=3}{}, cell{5}{11} = {c=2}{}, cell{6}{1} = {}{0.15\textwidth}, cell{6}{2} = {c=3}{0.15\textwidth}, cell{6}{5} = {c=2}{0.15\textwidth}, cell{6}{7} = {c=2}{0.15\textwidth}, cell{6}{9} = {c=3}{0.15\textwidth}, cell{6}{11} = {}{0.15\textwidth}, width=\textwidth, hlines, vlines, } 1 & & & & & & & & & & & \\ 2& & & & & & 2 & & & & & \\ 3 & & & & 3 & & & & 3 & & & \\ 4 & & & 4 & & & 4& & &4& & \\ 5 & & 5 & & & 5 & & 5 & & & 5 & \\ 6Loerm Ipsum&6 Lorem Ipsum & & & 6Lorem Ipsum& &6 Lorem Ipsum& & 6Lorem Ipsum& & &6 Lorem Ipsum \end{longtblr} \end{table} \end{document} 
3
  • 2
    Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for the users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Commented May 28 at 20:20
  • 1
    Unrelated, but neither the table environment nor the \centering make much sense Commented May 28 at 20:21
  • 1
    reducing the space between columns might be enough for one more column... Commented May 28 at 20:22

1 Answer 1

3

Since you select c column types, column widths is adopted to the widest text in their cells. This can be limited, if you instead c select X[c] column type, which force longer text to be broken into several lines if it is longer than width of columns (calculated by LaTeX), for example as is shown on table image below:

enter image description here

(red lines indicate page layout).

This table is generated by:

\documentclass{scrbook} %--------------- show page layout. don't use in a real document! \usepackage{showframe} \renewcommand\ShowFrameLinethickness{0.15pt} \renewcommand*\ShowFrameColor{\color{red}} % \usepackage{lipsum} % for dummy text %---------------------------------------------------------------% \usepackage{tabularray} \begin{document} %\begin{table} long table should not be inserted into float \begin{longtblr}[]{%width=\linewidth, colsep=3pt, % <--- new colspec={*{12}{X[c]}}, % <--- changed cells = {font=\small}, % <--- for better fiting text into cells cell{1}{1} = {c=12}{}, cell{2}{1} = {c=6}{}, cell{2}{7} = {c=6}{}, cell{3}{1} = {c=4}{}, cell{3}{5} = {c=4}{}, cell{3}{9} = {c=4}{}, cell{4}{1} = {c=3}{}, cell{4}{4} = {c=3}{}, cell{4}{7} = {c=3}{}, cell{4}{10} = {c=3}{}, cell{5}{1} = {c=2}{}, cell{5}{3} = {c=3}{}, cell{5}{6} = {c=2}{}, cell{5}{8} = {c=3}{}, cell{5}{11} = {c=2}{}, cell{6}{2} = {c=3}{}, cell{6}{5} = {c=2}{}, cell{6}{7} = {c=2}{}, cell{6}{9} = {c=3}{}, hlines, vlines, hspan=minimal % <--- new } 1 & & & & & & & & & & & \\ 2 & & & & & & 2 & & & & & \\ 3 & & & & 3 & & & & 3 & & & \\ 4 & & & 4 & & & 4& & &4& & \\ 5 & & 5 & & & 5 & & 5 & & & 5 & \\ 6 Lorem Ipsum &6 Lorem Ipsum & & & 6 Lorem Ipsum& &6 Lorem Ipsum& & 6 Lorem Ipsum& & &6 Lorem Ipsum\\ 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 &10 &11 &12 \end{longtblr} %\end{table} long table should not be inserted into float \end{document} 

Futher measures can be beside reducing space between columns also further reducing font size in table.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.