
Estoy intentando crear una tabla con varias filas en una celda.
\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}
Recibo esto como resultado.
Tenga en cuenta que las líneas verticales no se conectan con la línea horizontal. ¿Cómo corregir esto?
También quiero hacer esta tabla dentro de mytablebox, pero cuando descomento \begin{mytablebox} muestra el error "No en modo par externo. \centering". ¿Cómo puedo hacer que esto funcione?
Respuesta1
Elimine el salto de línea \\
después \hline
(como dijo TeXnician) y mueva su entorno dentro del table
entorno.
\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}
Respuesta2
El espacio entre la línea y el texto se produce mediante un salto de línea superfluo.
Y no puede utilizar un entorno flotante en un cuadro mdframed. Simplemente retírelo y úselo \captionof
en su lugar.
Luego notarás que tu tabla es demasiado ancha para tu cuadro (más ancha que el ancho del texto).
Puede deshacerse de eso fácilmente eligiendo uno \textwidth
que sea más ancho o corrigiendo sus columnas. Con m{4cm}
(y con márgenes de página para mostrar que encaja):
\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}