0

I am trying to create a table with multiple rows in a cell.

\documentclass{article}

\usepackage{array}
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25}


\newmdenv[%
linecolor=ocre,
backgroundcolor=ocre!10,
linewidth=1pt]{mytablebox}

\begin{document}
    %\begin{mytablebox}
        \begin{table}
            \centering
            \caption{Crane shop activities.}
            \label{table:crane_shop_activities}
            \begin{tabular}{|m{2cm}| m{5cm}| m{5cm}|}
                \hline\\
                \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
                \hline\\
                \multirow{3}{*}{Tower Car} & Mark II, III, IV & \multirow{3}{5cm}{Earlier Manufacturing, currently only POH}\\
                & DHTC (Diesel Hydraulic Tower Car) & \\
                & 8 Wheeler &\\
                \hline\\
                \multirow{2}{*}{20T Crane} & Mechanical & \multirow{2}{5cm}{Both Manufacturing and POH}\\
                & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
                \hline\\
                \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
                & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
                \hline
            \end{tabular}
        \end{table}
    %\end{mytablebox}
\end{document}

I'm getting this as output.

Please note that vertical lines are not connecting to horizontal line. How to correct this?

I also want to make this table inside mytablebox, but when I uncomment \begin{mytablebox} it shows "Not in outer par mode. \centering" error, How can I make this work?

Table output

  • 1
    Remove the \\ after \hline. – TeXnician Jun 29 '17 at 14:44
  • And remove the table environment to make your box. – TeXnician Jun 29 '17 at 14:46
1

Remove the linebreak \\ after \hline (as TeXnician said) and move your environment inside the table environment.

\documentclass{article}

\usepackage{array}
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25}


\newmdenv[%
linecolor=ocre,
backgroundcolor=ocre!10,
linewidth=1pt]{mytablebox}

\begin{document}
    \begin{table}
        \centering
        \caption{Crane shop activities.}
        \label{table:crane_shop_activities}
        \begin{mytablebox}
            \begin{tabular}{|m{15mm}| m{40mm}| m{45mm}|}
                \hline
                \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
                \hline
                \multirow{3}{*}{Tower Car} & Mark II, III, IV & \multirow{3}{5cm}{Earlier Manufacturing, currently only POH}\\
                & DHTC (Diesel Hydraulic Tower Car) & \\
                & 8 Wheeler &\\
                \hline
                \multirow{2}{*}{20T Crane} & Mechanical & \multirow{2}{5cm}{Both Manufacturing and POH}\\
                & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
                \hline
                \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
                & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
                \hline
            \end{tabular}
        \end{mytablebox}
    \end{table}
\end{document}

enter image description here

1

Your space between the line and the text is produced by an superfluous line break.

And you cannot use a floating environment in a mdframed box. Just remove it and use \captionof instead.

You will then notice that your table is too wide for your box (wider than the text width).

table and mdframed

You can easily get rid of that by choosing a \textwidth which is wider or correcting your columns. With m{4cm} (and with page margins to show that it fits):

corrected

\documentclass{article}

\usepackage{array}
\usepackage{mdframed}
\usepackage{multirow}
\usepackage{xcolor} % Required for specifying colors by name
\usepackage{caption}
\definecolor{ocre}{RGB}{243,102,25}


\newmdenv[%
linecolor=ocre,
backgroundcolor=ocre!10,
linewidth=1pt]{mytablebox}

\begin{document}
    \begin{mytablebox}
            \centering
            \captionof{table}{Crane shop activities.}
            \label{table:crane_shop_activities}
            \begin{tabular}{|m{2cm}| m{5cm}| m{5cm}|}
                \hline
                \textbf{Category} & \textbf{Types} & \textbf{Activities}\\
                \hline
                \multirow{3}{*}{Tower Car} & Mark II, III, IV & \multirow{3}{5cm}{Earlier Manufacturing, currently only POH}\\
                & DHTC (Diesel Hydraulic Tower Car) & \\
                & 8 Wheeler &\\
                \hline
                \multirow{2}{*}{20T Crane} & Mechanical & \multirow{2}{5cm}{Both Manufacturing and POH}\\
                & Hydraulic (retrofitting of mechanical superstructure with hydraulic one) & \\
                \hline
                \multirow{2}{*}{140T Crane} & Old Design Crane & POH, MLR, SP MLR\\
                & New Design Crane & Manufacturing, POH, MLR, SP MLR\\
                \hline
            \end{tabular}
    \end{mytablebox}
\end{document}
  • 1
    Removed my answer in which I solved the issue but with bad practices. – Gaurish Gangwar Jun 29 '17 at 17:44

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.