大家好。我需要将文本块括在大方括号中。类似这样的内容(我需要或多或少地复制它):
我读到过使用 tikz 可以实现这一点,但我对这个包一无所知。甚至,我在这篇文章中找到了一段代码,它重现了类似的东西,但带有括号: 在正文旁边添加大括号 代码如下:
\documentclass{article}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\usetikzlibrary{decorations.pathreplacing}
\newtcolorbox{rightbrace}{%
enhanced jigsaw,
breakable, % allow page breaks
frame hidden, % hide the default frame
overlay={%
\draw [
fill=none, % fill paper
decoration={brace,amplitude=0.5em},
decorate,
ultra thick,
gray,
]
% right line
(frame.north east)--(frame.south east);
},
% paragraph skips obeyed within tcolorbox
parbox=false,
}
\begin{document}
\begin{itemize}
\item First line
\begin{rightbrace}
\item Second line
\item Third line, which is quite long and seemingly tedious in the extreme
\item Fourth line, which isn't as long as the third
\end{rightbrace}
\item Fifth line
\end{itemize}
\begin{rightbrace}
\lipsum[1]
\end{rightbrace}
\lipsum[2]
\end{document}
我怎样才能将方括号放在文本块周围?(使用 tikz、tcolobox 或任何有用的包都可以)。
感谢您的帮助。
答案1
我修改了代码以匹配您的图片。
这是输出:
代码如下:
\documentclass{article}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}
\newtcolorbox{squarebrackets}[2][]{%
empty,
breakable,
boxsep=0pt,boxrule=0pt,left=5mm,right=5mm,
toptitle=3mm,bottomtitle=1mm,
title=\colorbox{yellow}{#2},
coltitle=black,
fonttitle=\bfseries,
underlay={%
\draw[gray!50,line width=1mm]
([xshift=5mm,yshift=-0.5mm]frame.north west)--
([xshift=0.5mm,yshift=-0.5mm]frame.north west)--
([xshift=0.5mm,yshift=0.5mm]frame.south west)--
([xshift=5mm,yshift=0.5mm]frame.south west)
([xshift=-5mm,yshift=-0.5mm]frame.north east)--
([xshift=-0.5mm,yshift=-0.5mm]frame.north east)--
([xshift=-0.5mm,yshift=0.5mm]frame.south east)--
([xshift=-5mm,yshift=0.5mm]frame.south east)
;
},
% paragraph skips obeyed within tcolorbox
parbox=false,#1
}
\begin{document}
\lipsum[1]
\begin{squarebrackets}{Corolario}
\lipsum[2]
\end{squarebrackets}
\lipsum[3]
\end{document}