tikz 节点,自动支撑以放下下降器

tikz 节点,自动支撑以放下下降器

我正在使用(巨大的)tikz 图片来模拟可填写的表格。因此,节点中的文本必须对齐。

为了处理下降线,我创建了一个支柱,当出现“p”、“g”、“q”等时,它会将文本“放回”基线。但每次都必须手动执行此操作很烦人。此外,根据 \textls 和 \textrm,字符具有不同的下降线特征(例如“Q”和“/”)。

所有用户文本均在创建的命令{}中输入,例如
\newcommand{\ntstyle}{frequent singleton A or K}
目前,所有命令均放入格式化块中,
\newcommand{\regtext}[1]{\scriptsize \usertext{\textls[-70]{#1}}}
因此我们有类似这样的节点
\node [right] at (x, y) {\regtext{ntstyle}}

我想知道我是否可以修复我的格式命令,以便它可以查看输入并自动确定是否需要下降支柱,而不是强迫用户每次都记住。

例子:

\RequirePackage{tikz} %graphics tools. Also install ``ms'' package.
\RequirePackage{txfonts} %provides \varheartsuit and \vardiamondsuit
\RequirePackage{microtype} % allows us to stretch/shrink fonts to match
\RequirePackage[T1]{fontenc} % T1 font necessary to stretch and shrink
\RequirePackage{helvet} %provides Helvetica typeface
\RequirePackage{xifthen} %manipulate boolean values
\ProvidesPackage{template/mwe2022}

\newcommand{\tRegtext}[1]{\scriptsize \textsf{\textls[-70]{#1}}}
\newcommand{\usertext}{\ifthenelse{\boolean{serif}}{\textrm}{\textsf}}
\newcommand{\regtext}[1]{\scriptsize \usertext{\textls[-70]{#1}}}

\newboolean{serif}

%Two formatting commands, since TikZ places text blocks by their centers not
%their baselines: if you use p, y, or g, your text will look ``pushed upward'';
%if you use only lowercase letters, your text will look ``too high''.
\newcommand{\pfix}{\rule{0pt}{2.6mm}} %A way to re-center user text with p,y,g
\newcommand{\xfix}{\rule{0pt}{2.0mm}} %re-center text with no capital letters

% All coordinates of items inside here are given in millimeters
% from the bottom left corner of the card.
\newcommand{\drawconventioncard}{%
    \usetikzlibrary{scopes}%
    \usetikzlibrary{calc}%needed to position stuff in strings
    \begin{tikzpicture}[xscale=0.1,yscale=0.1,
    ];
    % draw a box around everything
    \draw (0, 0) -- (0, 215) -- (203, 215) -- (203, 0) -- cycle;

    \node [right] at (104, 200.7) {\tRegtext{Min Expected HCP when Balanced: Opening}};
    \node at (162, 201) {\regtext{\minHCPopen}};
    \node [right] at (168, 200.7) (mhbr) {\tRegtext{Responding}};
    \node at (191, 201) {\regtext{\minHCPresp}};

    \end{tikzpicture}%
}%end of \drawconventioncard

并形成:

\documentclass[12pt]{article}
% the card is 8'' wide, so the margins are very narrow to fit on letter size paper:
\usepackage{template/mwe}
\usepackage[left=0mm,right=5mm,top=20mm]{geometry}
\begin{document}

\setboolean{serif}{true}
\newcommand{\minHCPopen}{peter\pfix{}}  % **I want this to not have to be manual**
\newcommand{\minHCPresp}{Paul}

\drawconventioncard
\end{document}

使用 \pfix{} 支撑:带 pfix

但删除 \pfix{} 后,它看起来像:无后缀

答案1

我认为这就是你想要的。通过使用节点的相对位置,并明确设置文本高度和文本深度,你将更好地对齐节点中的文本。我为每个节点绘制了框架,以显示效果。你可以注释掉那一行,让它没有框架。

\documentclass[12pt]{article}
\usepackage{tikz} %graphics tools. Also install ``ms'' package.
\usepackage{txfonts} %provides \varheartsuit and \vardiamondsuit
\usepackage{microtype} % allows us to stretch/shrink fonts to match
\usepackage[T1]{fontenc} % T1 font necessary to stretch and shrink
\usepackage{helvet} %provides Helvetica typeface
\usepackage{xifthen} %manipulate boolean values
\newcommand{\tRegtext}[1]{\scriptsize \textsf{\textls[-70]{#1}}}
\newcommand{\usertext}{\ifthenelse{\boolean{serif}}{\textrm}{\textsf}}
\newcommand{\regtext}[1]{\scriptsize \usertext{\textls[-70]{#1}}}

\newboolean{serif}

%Two formatting commands, since TikZ places text blocks by their centers not
%their baselines: if you use p, y, or g, your text will look ``pushed upward'';
%if you use only lowercase letters, your text will look ``too high''.
\newcommand{\pfix}{\rule{0pt}{2.6mm}} %A way to re-center user text with p,y,g
\newcommand{\xfix}{\rule{0pt}{2.0mm}} %re-center text with no capital letters
% All coordinates of items inside here are given in millimeters
% from the bottom left corner of the card.
\newcommand{\drawconventioncard}{%
    \usetikzlibrary{scopes}%
    \usetikzlibrary{calc}%needed to position stuff in strings
    \begin{tikzpicture}[
    every node/.style={
    draw, % comment this to node without frame
    minimum size=20pt,
    text depth=.1\baselineskip,
    text height=.5\baselineskip,
    },
    xscale=0.1,yscale=0.1,
    ];
    % draw a box around everything
    \draw (0, 0) -- (0, 215) -- (203, 215) -- (203, 0) -- cycle;

    \node (o) [right] at (104, 200.7) {\tRegtext{Min Expected HCP when Balanced: Opening}};
    \node [anchor=west,right=0.5em]  at (o.east) {\regtext{\minHCPopen}};
    \node [right] at (168, 200.7) (r) {\tRegtext{Responding}};
    \node [anchor=west,right=0.5em] at (r.east) {\regtext{\minHCPresp}};

    \end{tikzpicture}%
}%end of \drawconventioncard
% the card is 8'' wide, so the margins are very narrow to fit on letter size paper:
%\usepackage{template/mwe}
\usepackage[left=0mm,right=5mm,top=20mm]{geometry}
\begin{document}

\setboolean{serif}{true}
\newcommand{\minHCPopen}{peter}  % **I want this to not have to be manual**
\newcommand{\minHCPresp}{Paul}

\drawconventioncard
\end{document}

在此处输入图片描述

相关内容