自定义 mdframed 框和表

自定义 mdframed 框和表

目前我正在使用 mdframed 框来围绕我的桌子。

\documentclass{article}

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

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


\newenvironment{mytablebox}
{
    \begin{Tablebox}
        
    }
    {
    \end{Tablebox}
}



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

它产生输出: 图片1

但我试图获得如下输出: 图片2

任何与此类似的东西都可以。我该怎么做?

我尝试这样做:

    \newenvironment{mytablebox}[1]
    {
        \begin{Tablebox}
            \textcolor{ocre}{#1~}
        }
        {
        \end{Tablebox}
    }

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

但它不起作用,而且我刚刚了解到使用 captionof 和 longtable 并不是正确的做法。

答案1

这是自定义标签格式的简短版本。如果您不想从定义中:删除。#2

表格标题

\documentclass{article}

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

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

\DeclareCaptionFormat{myformat}{\parbox{\linewidth}{
    \centering #1#2\\
    #3}}
\DeclareCaptionFont{lfont}{\color{orange}\Large\bfseries}
\DeclareCaptionFont{tfont}{\color{orange}}
\captionsetup[table]{labelfont=lfont,font=tfont,format=myformat}

\newenvironment{mytablebox}
{
    \begin{Tablebox}

    }
    {
    \end{Tablebox}
}



\begin{document}
        The various activities which are performed in the Crane shop are 
given in table \ref{table:crane_shop_activities}.
        \begin{mytablebox}
            \centering

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

            \end{longtable}
        \end{mytablebox}
\end{document}

相关内容