0

This is my table:

\documentclass{scrbook}
\usepackage{tabularx}
\begin{document}

\renewcommand{\arraystretch}{1.8}   %Presets from my institute
\newcolumntype{M}{X<{\vspace{4pt}}} %Presets from my institute

\begin{table}[!h]
\begin{tabularx}{\textwidth}{| M | M | M |}
\hline
& \textbf{Some text} & \textbf{some text that is too long for this column}\\[-3ex]
\hline
\textbf{text} & a number & a number\\
\hline
\textbf{text} & a number & a number\\
\hline
\textbf{text} & a number & a number\\
\hline
\end{tabularx}
\end{table}

\end{document}

With this output:

My table

I want to decrease the width of the first column (and consequently increase the width of the second and third column) so that the text of the third column fits in one line.

I searched a lot but could not find a solution that I understood and that worked for me.
Thanks in advance!

3
  • 1
    Did you already try with "l" instead of the first "M"?
    – leandriis
    Feb 2, 2021 at 11:49
  • I would guess columns 1 and 2 should both be l not M (also why the [-3ex] making the rule over-print the text? Feb 2, 2021 at 11:57
  • Thanks guys, that actually was the solution. I was so caught up in the issue that I tried a lot of complicated approaches but not the simple one. [-3ex] was there because without it the row was too high. Now with the "l" instead of the "M" in the first column, it works without the [-3ex].
    – Matthias
    Feb 2, 2021 at 12:56

1 Answer 1

0
\documentclass{scrbook}
\usepackage{tabularx}
\begin{document}

\renewcommand{\arraystretch}{1.8}   %Presets from my institute
\newcolumntype{M}{X<{\vspace{4pt}}} %Presets from my institute

\begin{table}[!h]
\begin{tabular}{
  |p{\dimexpr.10\linewidth-2\tabcolsep-1.3333\arrayrulewidth}% column 1
  |p{\dimexpr.25\linewidth-2\tabcolsep-1.3333\arrayrulewidth}% column 2
  |p{\dimexpr.65\linewidth-2\tabcolsep-1.3333\arrayrulewidth}|% column 3
  }
\hline
& \textbf{Some text} & \textbf{some text that is too long for this column}\\
\hline
\textbf{text} & a number & a number\\
\hline
\textbf{text} & a number & a number\\
\hline
\textbf{text} & a number & a number\\
\hline
\end{tabular}
\end{table}

\end{document}

You can change the dimexp values to match 1 according to your data

This is the end result

1
  • Thanks a lot. This also solves my problem. I tried that approach before but forgot to change "tabularx" to "tabular" and remove the "{\textwidth}". Therefore it didn't work back then.
    – Matthias
    Feb 2, 2021 at 13:07

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.