表格打印不正确

表格打印不正确

我正在尝试创建一个单元格中包含多行的表格。

\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}

我得到这个作为输出。

请注意垂直线没有连接到水平线。如何纠正这个问题?

我也想在 mytablebox 中制作这个表格,但是当我取消注释 \begin{mytablebox} 时,它显示“不在外部模式。\centering”错误,我该如何让它工作?

表输出

答案1

\\删除后面的换行符\hline(正如 TeXnician 所说)并将您的环境移到环境内部table

\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}

在此处输入图片描述

答案2

行与文本之间的空格是由多余的换行符产生的。

而且您不能在 mdframed 框中使用浮动环境。只需将其移除并改用\captionof即可。

然后您会注意到您的表格对于您的框来说太宽(比文本宽度宽)。

表格和 mdframed

\textwidth您可以通过选择更宽的或更正列来轻松摆脱这种情况。使用m{4cm}(并使用页边距来显示它适合):

更正

\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}

相关内容