字间距文本打字机文本,字间空格宽度相同

字间距文本打字机文本,字间空格宽度相同

我喜欢使用 LaTeX 将一些文本放在现有 PDF 表单的顶部,这样我就不必手动填写了。为此,我使用microtype字母间距功能将大写文本拉伸到表单的字符框中。当tt使用字体时,这种方法效果很好,除非我在文本中有空格。然后空格似乎宽度较短,这会使所有后续字符都太靠左,以至于它们接触到框线,我尽量避免这种情况。

我怎样才能microtype使单词间的空格\textls和普通字符一样呢tt

或者,有没有办法在使用不同字体的同时获得等宽文本,例如\sffamily

由于此代码是表单填写包的原型,因此我考虑进行一些手动调整,例如将单词分开并将它们分开放置,这对我来说并不适合。

示例表格:

当前面有空格时,查看放错的第二个名字(MANFRED)和国家名称(MUSTERLAND)。

在此处输入图片描述

示例代码:
\documentclass[multi=page,border=0,preview]{standalone}
\usepackage{tikz}
\usepackage[tracking=true]{microtype}

\begin{document}
\edef\tempbox{\csname @tempboxa\endcsname}%
\sbox\tempbox{\includegraphics[page=1]{formular.pdf}}%
\begin{page}
\begin{tikzpicture}[x=\wd\tempbox,y=-\ht\tempbox]
\iffalse
\draw [ultra thin,black!10] (0,0) grid [step=2mm] (1, 1);
\draw [very thin,black!50] (0,0) grid [step=1cm] (1, 1);
\pgfmathtruncatemacro\xmax{\wd\tempbox/1cm}
\pgfmathtruncatemacro\ymax{\ht\tempbox/1cm}
\foreach \n in {0,...,\xmax} \node [font=\sffamily\tiny, anchor=north west] at (\n cm, 0) {\n} ;
\foreach \n in {1,...,\ymax} \node [font=\sffamily\tiny, anchor=north west] at (0, -\n cm) {\n} ;
\fi
\node [anchor=north west,inner sep=0pt, outer sep=0pt] {\usebox\tempbox};
%\draw [help lines] (0,0) grid [xstep=0.1\wd\tempbox,ystep=0.1\ht\tempbox] (1, 1);
\useasboundingbox (0,0) rectangle (1,1);

\begin{scope}[x=1cm, y=-1cm,anchor=base west,font=\ttfamily,inner sep=0pt, outer sep=0pt]
\SetTracking{ encoding = *}{ 618 }
\def\placetext#1#2{\node at (#1) {\textls{\MakeUppercase{#2}}};}
\node [inner sep=0pt] at (7.75, 8.825) {$\times$};
%\node [inner sep=0pt] at (8.675, 8.825) {$\times$};
\placetext{2.6, 9.4}{MUSTERMAN}
\placetext{2.6, 10.25}{MAX MANFRED}
\placetext{2.6, 11.1}{MUSTERSTRASSE}
\placetext{16.7, 11.1}{1234}
\placetext{2.6, 11.95}{98765}
\placetext{5.5, 11.95}{MUSTERSTADT, Musterland}
\placetext{2.6, 12.8}{12}
\placetext{3.75, 12.8}{34}
\placetext{4.85, 12.8}{5678}
\placetext{7.15, 12.8}{MUSTERSTADT}

\placetext{2.6, 16.925}{MUSTERSTRASSE}
\placetext{16.7, 16.925}{1234}
\placetext{2.6, 17.85}{98765}
\placetext{5.1725, 17.85}{MUSTERSTADT}
\placetext{2.6, 18.75}{\MakeUppercase{[email protected]}}

\node [inner sep=0pt] at (2.615, 19.725) {\Large$\times$};
\end{scope}
\end{tikzpicture}
\end{page}

\end{document}

答案1

我添加了[spacing = {1200*,,}]可选参数\SetTracking。对于选择,1200我听从了@StevenSegletes 的回答,在对起点 microtype doc 示例顶部第 17 页进行了一些反复试验之后MICRO FINE TUNING : Tracking

\documentclass[multi=page,border=0,preview]{standalone}
\usepackage{tikz}
\usepackage[tracking=true]{microtype}

\begin{document}
\edef\tempbox{\csname @tempboxa\endcsname}%
\sbox\tempbox{\fboxsep-\fboxrule\fbox{\vbox to 29.7cm{\hsize21cm\noindent X\dotfill X\par
                    \vfill\noindent X\dotfill X\par}}}%
\begin{page}
\begin{tikzpicture}[x=\wd\tempbox,y=-\ht\tempbox]
\iffalse
\draw [ultra thin,black!10] (0,0) grid [step=2mm] (1, 1);
\draw [very thin,black!50] (0,0) grid [step=1cm] (1, 1);
\pgfmathtruncatemacro\xmax{\wd\tempbox/1cm}
\pgfmathtruncatemacro\ymax{\ht\tempbox/1cm}
\foreach \n in {0,...,\xmax} \node [font=\sffamily\tiny, anchor=north west] at (\n cm, 0) {\n} ;
\foreach \n in {1,...,\ymax} \node [font=\sffamily\tiny, anchor=north west] at (0, -\n cm) {\n} ;
\fi
\node [anchor=north west,inner sep=0pt, outer sep=0pt] {\usebox\tempbox};
%\draw [help lines] (0,0) grid [xstep=0.1\wd\tempbox,ystep=0.1\ht\tempbox] (1, 1);
\useasboundingbox (0,0) rectangle (1,1);

\begin{scope}[x=1cm, y=-1cm,anchor=base west,font=\ttfamily,inner sep=0pt, outer sep=0pt]
\SetTracking[spacing = {1200*,,}]{ encoding = *, }{ 618 }
\def\placetext#1#2{\node at (#1) {\textls{\MakeUppercase{#2}}};}
\node [inner sep=0pt] at (7.75, 8.825) {$\times$};
%\node [inner sep=0pt] at (8.675, 8.825) {$\times$};
\placetext{2.6, 9.4}{MUSTERMAN}
\placetext{2.6, 10.25}{MAX MANFRED}
\placetext{2.6, 11.1}{MUSTERSTRASSE}
\placetext{16.7, 11.1}{1234}
\placetext{2.6, 11.95}{98765}
\placetext{5.5, 11.95}{MUSTERSTADT, Musterland}
\placetext{2.6, 12.8}{12}
\placetext{3.75, 12.8}{34}
\placetext{4.85, 12.8}{5678}
\placetext{7.15, 12.8}{MUSTERSTADT}

\placetext{2.6, 16.925}{MUSTERSTRASSE}
\placetext{16.7, 16.925}{1234}
\placetext{2.6, 17.85}{98765}
\placetext{5.1725, 17.85}{MUSTERSTADT}
\placetext{2.6, 18.75}{\MakeUppercase{[email protected]}}

\node [inner sep=0pt] at (2.615, 19.725) {\Large$\times$};
\end{scope}
\end{tikzpicture}
\end{page}

\end{document}

在此处输入图片描述

答案2

我先从这个问题开始:如何改变单词间距?并进行了修改\spaceskip,扩大了1.2倍。

\documentclass{article}
\usepackage{tikz}
\usepackage[tracking=true]{microtype}
\def\placetext#1{\textls{\MakeUppercase{#1}}}
\begin{document}

\ttfamily

\placetext{x x x x x x x x x x x x x x x x x x x} (wrong)

\placetext{xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyx}

{\spaceskip=1.2\fontdimen2\font plus 1.2\fontdimen3\font minus 1.2\fontdimen4\font

\placetext{x x x x x x x x x x x x x x x x x x x} (fixed)}

\end{document}

在此处输入图片描述

可以将其\spaceskip合并到宏定义本身中,并分组以限制其范围:

\def\placetext#1{{%
  \spaceskip=1.2\fontdimen2\font plus 1.2\fontdimen3\font minus 1.2\fontdimen4\font%
  \textls{\MakeUppercase{#1}}%
}}

相关内容