![繪製一條短的字母間垂直線,而不影響字母間距](https://rvso.com/image/353369/%E7%B9%AA%E8%A3%BD%E4%B8%80%E6%A2%9D%E7%9F%AD%E7%9A%84%E5%AD%97%E6%AF%8D%E9%96%93%E5%9E%82%E7%9B%B4%E7%B7%9A%EF%BC%8C%E8%80%8C%E4%B8%8D%E5%BD%B1%E9%9F%BF%E5%AD%97%E6%AF%8D%E9%96%93%E8%B7%9D.png)
我想在字母之間繪製小而薄的分隔符,而不改變 Xetex 中的字母間距(跟踪)。這是一次失敗的嘗試\rule
:
\documentclass{minimal}
\setlength{\parindent}{0cm}
\usepackage{fontspec}
\setromanfont[LetterSpace=50.0]{Noto Serif}
\newcommand{\mysep}{\rule[0.125em]{1pt}{0.5em}}
\begin{document}
HLHHLLH\\
HL\mysep{}HHL\mysep{}LH
\end{document}
結果:
我希望上面兩行中的字母能夠準確地彼此對齊,儘管底行中有額外的分隔符號。我願意接受替代解決方案,例如在 tikz 上繪製內容,只要結果可以內聯、中間文字使用(例如,表格)。
答案1
下面的程式碼定義了一個命令\vlines[optional position]{letter sequence}
,以便輸入
Some text \vlines{HL|HHL|LH} some more text.
Some text \vlines[t]{HL|HHL|LH} some more text.
Some text \vlines[b]{HL|HHL|LH} some more text.
結果是
\documentclass{minimal}
\setlength{\parindent}{0cm}
% \usepackage{fontspec}
% \setromanfont[Scale=2,LetterSpace=50.0]{Noto Serif}
\newcommand{\mysep}{\rule[0.125em]{1pt}{0.5em}}
\makeatletter
\newcommand\vloop{\@ifnextchar|{\vloopa}{\vloopb}}
\makeatother
\newcommand\vloopa[1]{\let\sep\vline\vloop}
\newcommand\vloopb[1]%
{\ifx\relax#1%
\else
\sep
\let\sep\NoVline
#1%
\expandafter\vloop
\fi
}
\newcommand\sep{}
\newcommand\NoVline{\makebox[0.5em]{}}
\newcommand\Vline{\makebox[0.5em]{\mysep}}
\newcommand\vlines[2][]%
{\begin{tabular}[#1]{@{}l@{}}%
\let\vline\NoVline\def\sep{}\vloop#2\relax\\
\let\vline\Vline\def\sep{}\vloop#2\relax
\end{tabular}%
}
\begin{document}
Some text \vlines{HL|HHL|LH} some more text.
\bigskip
Some text \vlines[t]{HL|HHL|LH} some more text.
\bigskip
Some text \vlines[b]{HL|HHL|LH} some more text.
\end{document}
編輯:根據評論,只需要一行等距的字母,中間有分隔符號。這稍微簡化了程式碼。
\documentclass{minimal}
\newcommand{\mysep}{\rule[0.125em]{1pt}{0.5em}}
\makeatletter
\newcommand\vloop{\@ifnextchar|{\vloopa}{\vloopb}}
\makeatother
\newcommand\vloopa[1]{\let\sep\Vline\vloop}
\newcommand\vloopb[1]%
{\ifx\relax#1%
\else
\sep
\let\sep\NoVline
#1%
\expandafter\vloop
\fi
}
\newcommand\sep{}
\newcommand\NoVline{\makebox[0.5em]{}}
\newcommand\Vline{\makebox[0.5em]{\mysep}}
\newcommand\vlines[1]{\def\sep{}\vloop#1\relax}
\begin{document}
Some text \vlines{HL|HHL|LH} some more text.
\end{document}