如何在文本周围画一条线,但在一侧打开?

如何在文本周围画一条线,但在一侧打开?

我想做类似的事情\boxed{whatever},但盒子的一侧是打开的。类似以下的东西。

\documentclass{article}

\begin{document}

\[
\overline{\underline{abc |}}
\]

\end{document}

结果如下(虽然不太好看,但是概念上接近我想要的):

使用下划线、上划线和“|”的结果

我想有一种简单的方法可以满足我的需要,但我找不到它。

答案1

像这样 ?

使用 tcolorbox:

截屏

\documentclass{article}
\usepackage{tcolorbox}

\newtcbox{\boxed}{on line,colframe=black,colback=white,sharp corners,
before upper={\rule[-3pt]{0pt}{10pt}},boxrule=1pt,leftrule=0pt,
boxsep=0pt,left=2pt,right=1pt,top=1pt,bottom=.5pt}

\begin{document}

Quick brown fox \boxed{jumped} over the lazy dog.

\end{document}

答案2

\documentclass{article}

\begin{document}

\[
\begin{array}{@{}|@{\,}l@{}}
\hline
abc\\
\hline
\end{array}\quad\mbox{or}\quad
\begin{array}{@{}l@{\,}|@{}}
\hline
abc\\
\hline
\end{array}
\]

\end{document}

在此处输入图片描述

答案3

tikz 的答案:

\documentclass{article}
\usepackage{tikz}
\usepackage{parskip}
\setlength{\parskip}{15pt}
\newsavebox{\mybox}
\newcommand{\PutInsideOpenBox}[3][-,black]{\ifdefined\extraxskip\relax\else\xdef\extraxskip{1pt}\fi\ifdefined\extrayskip\relax\else\xdef\extrayskip{3.5pt}\fi\savebox{\mybox}{\vbox{\hbox{#3}}}\begin{tikzpicture}[outer sep=0,inner sep=0pt,baseline=#2]\node at ({\wd\mybox/2},{(\ht\mybox+\dp\mybox)/2}){\usebox{\mybox}};
\draw[#1]({-\extraxskip},{-\extrayskip})--({\wd\mybox+\extraxskip},{-\extrayskip})--({\wd\mybox+\extraxskip},{(\ht\mybox+\dp\mybox)+\extrayskip})--({-\extraxskip},{(\ht\mybox+\dp\mybox)+\extrayskip});\end{tikzpicture}}
\begin{document}

\[
\PutInsideOpenBox{0pt}{
abc
}\]

In text: \(\PutInsideOpenBox[-,thick,red]{0pt}{AbcD}\) that will expand in two lines and we will see that the baselineskip is slightly increased

Increasing borders:
\def\extraxskip{3pt}
\def\extrayskip{6pt}

In text: \(\PutInsideOpenBox[-,thick,red]{0pt}{AbcD}\) that will expand in two lines and we will see that the baselineskip is enough increased

An equation:

\[
\PutInsideOpenBox{2.5pt}{f(x)}=x\cdot \PutInsideOpenBox[-,blue]{2.5pt}{(y+1)}
\]

\end{document}

在此处输入图片描述

答案4

fbox包裹:

\documentclass{article}
\usepackage{fbox}

\begin{document}

\fbox[trb]{abc} \fbox[tlb]{abc}

\end{document}

在此处输入图片描述

相关内容