表格列印不正確

表格列印不正確

我正在嘗試創建一個單元格中包含多行的表格。

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

相關內容