如何制作恰好在侧边框上?

如何制作恰好在侧边框上?

这是一个 MWE:

\tcbox[enhanced,frame hidden,borderline={0.5pt}{0pt}{red,dashed}]{ab}

结果如下:
在此处输入图片描述

我希望只显示左边框。可以吗?
谢谢!

答案1

您可以使用borderline west以下选项:

\documentclass{article}
\usepackage{kantlipsum}         % for sample text
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\newtcbox{\mybox}[1][]{
   enhanced, frame hidden, borderline west = {0.5pt}{0pt}{red,dashed}, #1
}

% Variant using a `minipage`-style boxing technique (this allows
% multiple lines, \tcblower, etc.)
\newtcolorbox{myleftlinebox}[1][]{
   enhanced, frame hidden, borderline west = {0.5pt}{0pt}{red,dashed}, #1
}

\begin{document}

This is \mybox{the box} and what comes next.

\bigskip
This is \mybox[on line]{the same box but \texttt{on line}} and what comes
next.

\bigskip \noindent
Variant based on \verb|\newtcolorbox|:
\begin{myleftlinebox}
  \kant[1]
\end{myleftlinebox}

\end{document}

截屏

请注意,可以使用用 声明的样式来分解前面的示例\tcbset,例如:

\documentclass{article}
\usepackage{kantlipsum}         % for sample text
\usepackage{tcolorbox}
\tcbuselibrary{skins}

\tcbset{my left line/.style={
          enhanced, frame hidden, borderline west = {0.5pt}{0pt}{red,dashed}
}}

\newtcbox{\mybox}[1][]{my left line, #1}
\newtcolorbox{myleftlinebox}[1][]{my left line, #1}

\begin{document}

This is \mybox{the box} and what comes next.

\bigskip
This is \mybox[on line]{the same box but \texttt{on line}} and what comes
next.

\bigskip \noindent
Variant based on \verb|\newtcolorbox|:
\begin{myleftlinebox}
  \kant[1]
  \tcblower
  \kant[2]
\end{myleftlinebox}

\end{document}

截屏

相关内容