Tikz node, auto-strut to drop descenders

struttikz-pgf

I am using a (huge) tikz picture to emulate a fillable form. As a result, the text in the nodes has to line up.

To handle descenders, I have created a strut that "drops" the text back to the baseline in case of 'p','g','q' etc. But it is annoying to have to do this by hand every single time. Also, depending on \textls vs \textrm, characters have different descender characteristics (such as 'Q' and '/').

All user text is entered in a created command{}, so for instance
\newcommand{\ntstyle}{frequent singleton A or K}.
Currently, all the commands are dropped into formatting blocks like
\newcommand{\regtext}[1]{\scriptsize \usertext{\textls[-70]{#1}}}

so we have nodes like
\node [right] at (x, y) {\regtext{ntstyle}}.

I'm wondering if I can fix my formatting commands so that it can look at the input and determine if it needs the descender strut automatically, rather than forcing the user to remember every time.

Example:

\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

and form:

\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}

with \pfix{} strut :with pfix

but with \pfix{} removed, it looks like :no pfix

Best Answer

I think this is what you wanted. By using relative location of the nodes, and setting the text height and text depth explicitly, you will have better alignment of the text in the nodes. I draw the frame for each node, to show the effect. You can comment that line to make it without frame.

\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}

enter image description here