带半圆形末端的带框文本

带半圆形末端的带框文本

我想要一些带有半圆形末端的盒子,当它们足够短时,可以缩小为简单的圆形。我还希望这些周围框架的高度保持不变。使用 fancybox 包,我可以尝试使用细线或粗线来实现这一点,但它并不能在所有情况下都给出足够的结果。

\documentclass{scrartcl}

\usepackage{fancybox}

\cornersize*{1em}

\begin{document}

Using thicklines yields the best results : simple digits are almost perfectly surrounded by 
circles\footnote{Except in footnotes  such as this one \Ovalbox{1} although \Ovalbox{123} looks better.} \Ovalbox{1}, \Ovalbox{2}. Multiple digit numbers also look good, such as \Ovalbox{123}. However,
while some simple mathematical expressions have something close to
proper semi-circular ends, such as \Ovalbox{$v-1$}, others, such as the simple \Ovalbox{$v$}, apparently fail to do so as the ends are vertical and the height is too small.  I could possibly fix the latter by
having something like \Ovalbox{\vphantom{1}$v$}. Still, this leaves the problem of the footnotes.

Using thinlines does not look quite as good: simple digits with circles around are definitely not framed
adequately\footnote{And note this \ovalbox{1} although \ovalbox{123} looks better.} \ovalbox{1}, \ovalbox{2}. Multiple digit numbers look better, such as \ovalbox{123}. And here are the same examples as above using mathematical expressions: \ovalbox{$v-1$}, and \ovalbox{$v$}, the latter being clearly not satisfactory.

Finally, for circles, here is a comparison using a combination of\\ \LaTeX primitives: {\Large\textcircled{\small 1}} and the fancybox construct
\Ovalbox{1}. Looking at these two, on the same line, is helpful in noticing that the fancybox macro does not yield a perfect circle in this case.

\end{document}

编辑:我最终使用了基于 tikz 的建议,用 替换了inner sep=0.4exstyle 参数,minimum height=10pt使其与我完整文档中用 绘制的图形更加一致tikz-graph

答案1

将序言改为

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{shapes.misc}
\tikzset{%
    node thick/.style={inner sep=0.4ex,
        draw, rounded rectangle, thick,
    },
    node thin/.style={inner sep=0.4ex,
        draw, rounded rectangle, thin,
    }
}
\newcommand{\Ovalbox}[1]{\tikz[baseline=(tmp.base)] \node[node thick](tmp){#1};}
\newcommand{\ovalbox}[1]{\tikz[baseline=(tmp.base)] \node[node thin](tmp){#1};}

我得到以下信息:

在此处输入图片描述

在此处输入图片描述

您可以添加像minimum height和这样的键minimum width来使事物更加统一,并改变弧线(参见库tikz的手册shapes.misc)。

一个小附录tikzmark另外使用。

\documentclass{scrartcl}

\usepackage{tikz}
\usetikzlibrary{tikzmark,shapes.misc}
\tikzset{%
    node thick/.style={inner sep=0.4ex,
        draw, rounded rectangle, thick,
    },
    node thin/.style={inner sep=0.4ex,
        draw, rounded rectangle, thin,
    }
}
\newcounter{ovalbox}
\newcommand{\Ovalbox}[2][]{\stepcounter{ovalbox}%
\tikzmarknode[node thick,#1]{ovalbox-\theovalbox}{#2}}
\newcommand{\ovalbox}[2][]{\stepcounter{ovalbox}%
\tikzmarknode[node thin,#1]{ovalbox-\theovalbox}{#2}}

\begin{document}

Using thicklines yields the best results : simple digits are almost perfectly surrounded by 
circles\footnote{Except in footnotes  such as this one \Ovalbox{1} although \Ovalbox{123} looks better.} \Ovalbox{1}, \Ovalbox{2}. Multiple digit numbers also look good, such as \Ovalbox{123}. However,
while some simple mathematical expressions have something close to
proper semi-circular ends, such as \Ovalbox{$v-1$}, others, such as the simple \Ovalbox{$v$}, apparently fail to do so as the ends are vertical and the height is too small.  I could possibly fix the latter by
having something like \Ovalbox{\vphantom{1}$v$}. Still, this leaves the problem of the footnotes.

Using thinlines does not look quite as good: simple digits with circles around are definitely not framed
adequately\footnote{And note this \ovalbox{1} although \ovalbox{123} looks better.} \ovalbox{1}, \ovalbox{2}. Multiple digit numbers look better, such as \ovalbox{123}. And here are the same examples as above using mathematical expressions: \ovalbox{$v-1$}, and \ovalbox{$v$}, the latter being clearly not satisfactory.

Finally, for circles, here is a comparison using a combination of\\ \LaTeX primitives: {\Large\textcircled{\small 1}} and the fancybox construct
\Ovalbox{1}. Looking at these two, on the same line, is helpful in noticing that the fancybox macro does not yield a perfect circle in this case.

Let's now see what \verb|\tikzmarknode| buys us:
\[
 \sum\limits_{\ovalbox{k}=1}^{\Ovalbox{\infty}}
 \ovalbox{k}=\Ovalbox[draw=red]{-\frac{1}{12}}
\]
\begin{tikzpicture}[overlay,remember picture]
\draw[latex-] (ovalbox-17) -- ++(-150:1) 
node[anchor=30,node thick,align=center]{automatically\\ in math mode and\\
correct size};
\draw[latex-] (ovalbox-19) -- ++(-60:1) 
node[anchor=150,node thick,align=center]{automatically\\ in math mode and\\
correct size};
\draw[latex-] (ovalbox-20) -- ++(15:1) 
node[anchor=-165,node thick,align=center]{automatically\\ in math mode and\\
correct size};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

并不完美,但你可以尝试tcbox(来自tcolorbox

\documentclass{scrartcl}

%\usepackage{fancybox}
\usepackage[most]{tcolorbox}
\newtcbox{\myovalbox}[1][black]{
    on line, arc=6pt, 
    colback=white, colframe=#1, 
    before upper={\rule[-2pt]{0pt}{11pt}},
    boxsep=0pt, boxrule=1pt,
    left=4pt, right=4pt,
    top=1pt, bottom=1pt}

%\cornersize*{1em}

\begin{document}

Using thicklines yields the best results : simple digits are almost perfectly surrounded by 
circles\footnote{Except in footnotes  such as this one \myovalbox{1} although \myovalbox{123} looks better.} \myovalbox{1}, \myovalbox{2} %\myovalbox{1}, \myovalbox{123} . 
Multiple digit numbers also look good, such as \myovalbox{123}. However,
while some simple mathematical expressions have something close to
proper semi-circular ends, such as \myovalbox{$v-1$}, others, such as the simple \myovalbox{$v$}, apparently fail to do so as the ends are vertical and the height is too small.  I could possibly fix the latter by
having something like \myovalbox{\vphantom{1}$v$}. Still, this leaves the problem of the footnotes.

Using thinlines does not look quite as good: simple digits with circles around are definitely not framed
adequately\footnote{And note this \myovalbox{1} although \myovalbox{123} looks better.} \myovalbox{1}, \myovalbox{2}. Multiple digit numbers look better, such as \myovalbox{123}. And here are the same examples as above using mathematical expressions: \myovalbox{$v-1$}, and \myovalbox{$v$}, the latter being clearly not satisfactory.

Finally, for circles, here is a comparison using a combination of\\ \LaTeX primitives: {\Large\textcircled{\small 1}} and the fancybox construct
\myovalbox{1}. Looking at these two, on the same line, is helpful in noticing that the fancybox macro does not yield a perfect circle in this case.

\end{document}

在此处输入图片描述

相关内容