如何将一系列 TikZ 图片在基线对齐

如何将一系列 TikZ 图片在基线对齐

我正在尝试使用 TikZ 对齐一系列由字母组成的图片。尝试了几乎所有的按键组合后,baseline显然我遗漏了一些东西。这是 MWE(目前正在使用近似手册进行调整baseline=-4pt)。从图像中可以明显看出,调整仅适用于第一个字母。我该如何解决这个问题?

在此处输入图片描述

\documentclass{article}
\usepackage{pgf,tikz}
\makeatletter
\begin{document}
\gdef\drawfontframe#1{%
  \tikz[baseline=-4pt]{%
    \node[rectangle,draw,inner sep=0pt,outer sep=0pt] (X){#1};
    \draw[red, line width=0.4pt] (X.text)  circle(0.4pt)[fill=red] -- (X.base east);}%
}
\Huge A test %
\@tfor\next:=qwerty\do{%
\def\Z#1{\drawfontframe{#1}}%
\expandafter\Z\expandafter{\next}.%
}
\end{document}

答案1

正如评论中提到的,

  \tikz[baseline=(X.base)]{%

适用于此

在此处输入图片描述

\documentclass{article}
\usepackage{pgf,tikz}
\makeatletter
\begin{document}
\gdef\drawfontframe#1{%
  \tikz[baseline=(X.base)]{%
    \node[rectangle,draw,inner sep=0pt,outer sep=0pt] (X){#1};
    \draw[red, line width=0.4pt] (X.text)  circle(0.4pt)[fill=red] -- (X.base east);}%
}
\Huge A test %
\@tfor\next:=qwerty\do{%
\def\Z#1{\drawfontframe{#1}}%
\expandafter\Z\expandafter{\next}.%
}
\end{document}

以下是供参考的输出\listfiles(我正在 Ubuntu 上使用最新的 TeXLive 2011)

 *File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
     pgf.sty    2008/01/15 v2.10 (rcs-revision 1.12)
  pgfrcs.sty    2010/10/25 v2.10 (rcs-revision 1.24)
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v2.10 (rcs-revision 1.7)
graphicx.sty    1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
  pgfsys.sty    2010/06/30 v2.10 (rcs-revision 1.37)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2008/07/18  (rcs-revision 1.7)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v2.10 (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v2.10 (rcs-revision 1.1)
    tikz.sty    2010/10/13 v2.10 (rcs-revision 1.76)
  pgffor.sty    2010/03/23 v2.10 (rcs-revision 1.18)
 pgfkeys.sty    
 pgfkeys.code.tex
  pgffor.code.tex
    tikz.code.tex
supp-pdf.mkii
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)
epstopdf-base.sty    2010/02/09 v2.5 Base part for package epstopdf
  grfext.sty    2010/08/19 v1.1 Manage graphics extensions (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
 ***********

答案2

这是基于杰克的评论的解决方案。

评论:不需要加载pgf,则节点里面没有圆和线,解决办法很简单,可以使用没有名称的节点。

如果没有名字,就很难划清界限,我们需要使用current bounding box,但必须.5\pgflinewidth从每一边移除。

\documentclass{article}
\usepackage{tikz}
\makeatletter
\begin{document}

\gdef\drawfontframe#1{%
  \tikz[baseline]{%
  \node[anchor=base,draw,inner sep=0pt,outer sep=0pt] {#1};
  \filldraw[red, line width=0.4pt] ([xshift=.5\pgflinewidth]current bounding box.base west) circle(1pt)
    -- ([xshift=-.5\pgflinewidth]current bounding box.base east);
    }%
}%

\Huge A test %
\@tfor\next:=qwerty\do{%
\def\Z#1{\drawfontframe{#1}}%
\expandafter\Z\expandafter{\next}.%
}
\end{document}

在此处输入图片描述

相关内容