1

I would like to know how to manually insert a line break inside a table cell. Sometimes, this just looks so much better. However, I have not found anything that helped me out. I tried using \shortstack but the headspace to the horizontal lines is very small.

Here's my code:

\begin{table}[htbp]
\centering
    \resizebox{0.8\textwidth}{!}{
        \begin{tabular}{p{4cm} c|c}
            Parameter Category & Mathworks Toolbox & LMN Toolbox \\
            \hline
            Estimation Focus (Prediction or Simulation) & Focus-Parameter & kStepPrediction Value \\
            \hline
        \end{tabular}
        }
    \caption{ARX vs. OE Model Structure}
    \label{tab:modelParameters}
\end{table} 

I'd like to put '(Prediction or Simulation)' in a new line in the same cell under Estimation Focus.

Thank you in advance !

aladin
  • 115
  • 1
    Unrelated to the issue, but please don't use resizebox on tables as it will lead to inconsistent font sizes throughout the document. – leandriis Jan 05 '20 at 18:18
  • @leandriis Thank you for the tipp, I needed to resize the table for 1 special case which this one is. I cannot imagine of an other way to shrink the table size while retaining the font size. Can you ? :) – aladin Jan 05 '20 at 18:20
  • Regarding "shrink the table size while retaining the font size": The recommended way to do so would be reducing the column widths. Either manually or by using tabularx that allows you to specify an overall width of your table and adds a flexible width column type that lets your table adapt to this overall width. – leandriis Jan 05 '20 at 20:36
  • @leandriis Thank you! I will consider it. – aladin Jan 06 '20 at 21:09

1 Answers1

2

In a p type column, it's possible to use \par. In other column types, you can load the \makecell package and use the \makecell macro. Otherwise, you can use a small tabular with two rows in that cell.

\documentclass[a4paper]{article}
\usepackage{graphicx,makecell}

\begin{document}    

\begin{table}[htbp]
\centering
    \resizebox{0.8\textwidth}{!}{
        \begin{tabular}{m{4cm} c|c}
            Parameter Category & Mathworks Toolbox & LMN Toolbox \\
            \hline
            Estimation Focus\newline(Prediction or Simulation) & \makecell{Focus-Parameter\\Blabla ..} & kStepPrediction Value \\
            \hline
        \end{tabular}
        }
    \caption{ARX vs. OE Model Structure}
    \label{tab:modelParameters}
\end{table} 

\end{document}

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • thank you for your solution. However, I would also like to make newlines in c columns. Any clue ? – aladin Jan 05 '20 at 18:21
  • You can use makecell or insert a small tabular as I illustrated in my answer. I'll add an example if you need more help with a specific method. – AboAmmar Jan 05 '20 at 18:23
  • it would be really nice if you could add an example. For instance, you could add 'BlaBla' under 'Focus-Parameter'. – aladin Jan 05 '20 at 18:31
  • 1
    I've added an example, please see my edit. – AboAmmar Jan 05 '20 at 18:45
  • thank you! Your solution and the suggested solution from ''How to add a forced line break inside a table cell'' helped me a lot ! – aladin Jan 05 '20 at 18:56