0

I would like to merge two cells and at the same time have a break in the merged cell but I face an error.

How can I have $x \le 120$ and $y \le 200$ at two rows without being separated by a horizontal line?

Previously, I used makecell but I could not adjust the spacing between lines.

latex table rows

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{multirow}
\usepackage{tabularx}%
\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}


\begin{document}

\begin{table}[b!]
    \centering
    \caption{Test table}\label{table:test1}
    \setlength\extrarowheight{2pt}
    \begin{tabular}{ | L{5cm} | C{5cm} |}
        \hline
        Parameter & Value \\
        \hline \hline
        cost & 5 \$ \\
        \hline  
        number & 12 \\
        \hline  
        condition & \multirow{2}{*}{$x \le 120$, $y \le 200$}  \\
        ~&~\\
        \hline  
    \end{tabular}
\end{table}

\end{document}

3 Answers 3

4

No need for multirow, is it?

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{multirow}
\usepackage{tabularx}%
\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}


\begin{document}

\begin{table}[b!]
    \centering
    \caption{Test table}\label{table:test1}
    \setlength\extrarowheight{2pt}
    \begin{tabular}{ | L{5cm} | C{5cm} |}
        \hline
        Parameter & Value \\
        \hline \hline
        cost & 5 \$ \\
        \hline  
        number & 12 \\
        \hline  
        condition & $x \le 120$,  \\
                  & $y \le 200$ \\
        \hline  
    \end{tabular}
\end{table}

\end{document}

enter image description here

I have to say though that I think it looks better with less rules.

\documentclass{article}
\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\usepackage{booktabs} % for \toprule, \midrule, \bottomrule
\usepackage{caption} % will add some space between caption and table

\begin{document}
\begin{table}
    \centering
    \caption{Test table}\label{table:test1}
    \setlength\extrarowheight{2pt}
    \begin{tabular}{  L{5cm}  C{5cm} }
        \toprule
        Parameter & Value \\
        \midrule
        cost & \$5 \\
        number & 12 \\
        condition & $x \le 120$,  \\
                  & $y \le 200$ \\
        \bottomrule  
    \end{tabular}
\end{table}
\end{document}

enter image description here

2

Like this?

enter image description here

You need to use multirow in the right cell/column ...

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{multirow}
\usepackage{tabularx}%
\usepackage{array}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash}m{#1}}

\begin{document}  
\begin{table}[b!]
    \centering
    \caption{Test table}\label{table:test1}
\renewcommand\arraystretch{1.2}
    \begin{tabular}{ | L{5cm} | C{5cm} |}
        \hline
Parameter                   &   Value           \\
        \hline \hline
cost                        &   5 \$            \\
        \hline
number                      &   12 \\
        \hline
\multirow{2}*{condition}    &   $x \le 120$,    \\
                            &   $y \le 200$     \\
        \hline
    \end{tabular}
\end{table}
\end{document}

For better placement of caption try to use caption package.

2

Semantically, I prefer to use an aligned environment to split the equation. I added some minimal padding at the top and bottom of cells, with cellspace, so the cells contents is vertically centred. This way, I don't need the asymmetric \extrarowheight:

\documentclass{article}

\usepackage[lmargin=1.5cm,rmargin=1.5cm]{geometry}
\usepackage{caption, cellspace}%
\usepackage{array, amsmath}

\setlength\cellspacetoplimit{2pt}
\setlength\cellspacebottomlimit{2pt}

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}S{m{#1}}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}S{m{#1}}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}S{m{#1}}}

\begin{document}

\begin{table}[b!]
    \centering
    \caption{Test table}\label{table:test1}
    \begin{tabular}{ | L{5cm} | C{5cm} |}
        \hline
        Parameter & Value \\
        \hline \hline
        cost & 5\,\$ \\
        \hline
        number & 12 \\
        \hline
        condition & $\begin{aligned} x & \le 120,\\y & \le 200 \end{aligned}$ \\
        \hline
    \end{tabular}
\end{table}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .