答案1
答案2
具有简单框和规则的解决方案。填充和规则宽度可以使用与\fbox
长度\SquareCapSep
和中相同的方法配置\SquareCapRule
。
\documentclass{article}
\newlength{\SquareCapSep}
\newlength{\SquareCapRule}
\setlength{\SquareCapSep}{\fboxsep}
\setlength{\SquareCapRule}{\fboxrule}
\newcommand*{\SquareCap}[1]{%
\begingroup
\sbox0{#1}%
\leavevmode
\hbox{%
\vrule width\SquareCapRule
\vbox{%
\hrule height\SquareCapRule
\kern\SquareCapSep
\hbox{%
\kern\SquareCapSep
\box0\relax
\kern\SquareCapSep
}%
}%
\vrule width\SquareCapRule
}%
\endgroup
}
\begin{document}
\SquareCap{aaa}, \SquareCap{ab}, \SquareCap{Aa}
\setlength{\SquareCapSep}{.5\fboxsep}
\SquareCap{aaa}, \SquareCap{ab}, \SquareCap{Aa}
\end{document}
蒂克兹
TikZ 的解决方案。它还允许使用圆线帽和线连接:
\documentclass{article}
\usepackage{tikz}
\newlength{\SquareCapSep}
\newlength{\SquareCapRule}
\setlength{\SquareCapSep}{.5\fboxsep}
\setlength{\SquareCapRule}{\fboxrule}
\newcommand*{\SquareCap}[1]{%
\tikz[
baseline=(X.base),
inner sep=0pt,
line width=\SquareCapRule,
line cap=round,
line join=round,
]\draw
node(X){#1}
([xshift=-\SquareCapSep]X.south west)
-- ([xshift=-\SquareCapSep, yshift=\SquareCapSep]X.north west)
-- ([xshift=\SquareCapSep, yshift=\SquareCapSep]X.north east)
-- ([xshift=\SquareCapSep]X.south east)
;%
}
\begin{document}
\SquareCap{aaa}, \SquareCap{ab}, \SquareCap{Aa}, \SquareCap{xy}
\end{document}
如果垂直线应在基线处结束,则“南”应替换为“基”:
\documentclass{article}
\usepackage{tikz}
\newlength{\SquareCapSep}
\newlength{\SquareCapRule}
\setlength{\SquareCapSep}{.5\fboxsep}
\setlength{\SquareCapRule}{\fboxrule}
\newcommand*{\SquareCap}[1]{%
\tikz[
baseline=(X.base),
inner sep=0pt,
line width=\SquareCapRule,
line cap=round,
line join=round,
]\draw
node(X){#1}
([xshift=-\SquareCapSep]X.base west)
-- ([xshift=-\SquareCapSep, yshift=\SquareCapSep]X.north west)
-- ([xshift=\SquareCapSep, yshift=\SquareCapSep]X.north east)
-- ([xshift=\SquareCapSep]X.base east)
;%
}
\begin{document}
\SquareCap{aaa}, \SquareCap{ab}, \SquareCap{Aa}, \SquareCap{xy}
\end{document}
答案3
用于获取圆形帽的图片模式。使用expl3
可以轻松获取纯数字形式的高度(与 的比率\unitlength
)。
\documentclass{article}
\usepackage{pict2e,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\ltrfbox}{m}
{
\hspace{1pt}
\group_begin:
\hbox_set:Nn \l_tmpa_box { \hspace{\fboxsep} \strut #1 \hspace{\fboxsep} }
\dim_set:Nn \unitlength { \box_wd:N \l_tmpa_box }
\dim_set:Nn \l_tmpa_dim { \box_ht:N \l_tmpa_box }
\tl_set:Nx \l_tmpa_tl
{
\fp_eval:n { \dim_to_fp:n { \l_tmpa_dim } / \dim_to_fp:n { \unitlength } }
}
\begin{picture}(1,\l_tmpa_tl)
\put(0,0) { \box_use:N \l_tmpa_box }
\roundcap
\polyline(0,0)(0,\l_tmpa_tl)(1,\l_tmpa_tl)(1,0)
\end{picture}
\group_end:
\hspace{1pt}
}
\ExplSyntaxOff
\begin{document}
x \ltrfbox{aaa}, \ltrfbox{ab}, \ltrfbox{Aa}, \ltrfbox{xy} z
\end{document}