我想创建一个环境obj
(按章节编号),以便命令
\begin{obj}{Text 1}
Text 2
\end{obj}
生成以下内容(假设这是obj
第 1 章中的第一个环境):
\documentclass{report}
\usepackage[table]{xcolor}
\usepackage{tabularx,booktabs}
\usepackage{array}
\newcolumntype{/}{!{\textcolor{myblue}{\vrule width 1.5pt}}}
\newlength{\Oldarrayrulewidth}
\newcommand{\Cline}[2]{%
\noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
\noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
\noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}}
\definecolor{myblue}{RGB}{32,92,195}
\arrayrulecolor{myblue}
\begin{document}
\begin{center}
\begin{tabularx}{\textwidth}{ p{0.25in} p{0.05in} X }
\textcolor{myblue}{\textbf{1.1}} & \multicolumn{2}{X}{\textcolor{myblue}{Text 1}} \\
\Cline{2.5pt}{1-3}
& \multicolumn{1}{/p{0.05in}}{} & \multicolumn{1}{X}{\vspace{0.0pt}
Text 2} \\
\Cline{1.5pt}{2-3}
\end{tabularx}
\end{center}
\end{document}
答案1
作为宏来执行此操作会稍微容易一些:
\documentclass{report}
\usepackage[table]{xcolor}
\usepackage{tabularx,booktabs}
\usepackage{array}
\newcolumntype{/}{!{\textcolor{myblue}{\vrule width 1.5pt}}}
\newlength{\Oldarrayrulewidth}
\newcommand{\Cline}[2]{%
\noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
\noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
\noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}}
\definecolor{myblue}{RGB}{32,92,195}
\arrayrulecolor{myblue}
\newcounter{object}[chapter]
\renewcommand\theobject{\thechapter.\arabic{object}}
\newcommand\obj[2]{%
\refstepcounter{object}
\begin{center}
\begin{tabularx}{\textwidth}{ p{0.25in} p{0.05in} X }
\textcolor{myblue}{\textbf{\theobject}} & \multicolumn{2}{X}{\textcolor{myblue}{#1}} \\
\Cline{2.5pt}{1-3}
& \multicolumn{1}{/p{0.05in}}{} & \multicolumn{1}{X}{\vspace{0.0pt}
#2} \\
\Cline{1.5pt}{2-3}
\end{tabularx}
\end{center}
}
\begin{document}
\chapter{Some chapter}
\obj{Text 1}{Text 2}
\obj{Text 1}{Text 2}
\obj{Text 1}{Text 2}
\chapter{Some chapter}
\obj{Text 1}{Text 2}
\obj{Text 1}{Text 2}
\obj{Text 1}{Text 2}
\end{document}
将会生成(第二章):