PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Textplatzierung in Node



MC3330
01-02-2020, 20:51
Hallo,

ich habe für eine Aufgabe einen Text, der in eine Lineatur geschrieben wird. Dabei habe ich das Problem, dass der Text je nach Inhalt nicht korrekt in der Lineatur platziert wird.

Wenn keine g oder andere Buchstaben, die die dritte Zeile der Lineatur belegen, dann wird Text in der Lineatur zu tief angezeigt. Wenn kein Großbuchstabe oder Buchstaben wie t, h oder f enthalten sind, dann wird der text zu hoch angezeigt.

Meine Idee war bisher, dass ich dem Text am Ende die Buchstaben g und f hinzufüge, ohne das diese sichtbar sind. Ich habe ein wenig mit transparent und opacity gespielt, es aber nicht hinbekommen. Es gibt sicher auch elegantere Lösungen.

Hat da jemand eine Idee.

Viele Grüße
Swizz

Minimalbeispiel


\documentclass{article}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{math}
\usepackage{geometry}
\setlength\parindent{0pt}
\geometry{a4paper, top=10mm, left=12.5mm, right=5mm, bottom=5mm}

\newcommand\zwc[1][]{
\pgfkeys{
/zwc/zw/.initial=0,
/zwc/fs/.initial=0.5,
/zwc/lb/.initial=5
}%\
\pgfkeys{/zwc/.cd,#1}
\pgfkeysgetvalue{/zwc/zw}{\zw}
\pgfkeysgetvalue{/zwc/fs}{\fs}
\pgfkeysgetvalue{/zwc/lb}{\lb}
\tikzmath{
\lbc=\lb/2;
\fsc=\fs/3;
\fsh=\fs/6;
\linbot = -\fsh-\fsc;
\lintop = \fsh+\fsc;
}

\node[align=left,text width =\lb cm] {\fontsize{\fs cm}{0}\selectfont \zw};
\draw(-\lbc,\linbot)--(\lbc,\linbot)--(\lbc,\lintop)--(-\lbc,\lintop)--cycle;
\draw(-\lbc,-\fsh)--(\lbc,-\fsh);
\draw(-\lbc,\fsh)--(\lbc,\fsh);
\lb
}%\


\begin{document}

\begin{tikzpicture}
\zwc[zw = Zwölf]
\end{tikzpicture} Hier ist der Text zu tief

\vspace{1cm}

\begin{tikzpicture}
\zwc[zw = Neunzig]
\end{tikzpicture} Hier ist der Text richtig


\vspace{1cm}

\begin{tikzpicture}
\zwc[zw = eng]
\end{tikzpicture} Hier ist der Text zu hoch

\end{document}

rais
02-02-2020, 10:12
Du kannst dem \node Texthöhe und -tiefe mitgeben


\documentclass{article}
\usepackage{tikz}
\usepackage{fontspec}
\usetikzlibrary{math}
\usepackage{geometry}
\setlength\parindent{0pt}
\geometry{a4paper, top=10mm, left=12.5mm, right=5mm, bottom=5mm}

\newcommand\zwc[1][]{
\pgfkeys{
/zwc/zw/.initial=0,
/zwc/fs/.initial=0.5,
/zwc/lb/.initial=5
}%\
\pgfkeys{/zwc/.cd,#1}
\pgfkeysgetvalue{/zwc/zw}{\zw}
\pgfkeysgetvalue{/zwc/fs}{\fs}
\pgfkeysgetvalue{/zwc/lb}{\lb}
\tikzmath{
\lbc=\lb/2;
\fsc=\fs/3;
\fsh=\fs/6;
\linbot = -\fsh-\fsc;
\lintop = \fsh+\fsc;
}

\node[align=left,text width =\lb cm, text height=2ex, text depth=0.3ex] {\fontsize{\fs cm}{0}\selectfont \zw};
\draw(-\lbc,\linbot)--(\lbc,\linbot)--(\lbc,\lintop)--(-\lbc,\lintop)--cycle;
\draw(-\lbc,-\fsh)--(\lbc,-\fsh);
\draw(-\lbc,\fsh)--(\lbc,\fsh);
\lb
}%\


\begin{document}

\begin{tikzpicture}
\zwc[zw = Zwölf]
\end{tikzpicture} Hier ist der Text zu tief

\vspace{1cm}

\begin{tikzpicture}
\zwc[zw = Neunzig]
\end{tikzpicture} Hier ist der Text richtig


\vspace{1cm}

\begin{tikzpicture}
\zwc[zw = eng]
\end{tikzpicture} Hier ist der Text zu hoch

\end{document}

siehe dazu auch Ilkas Beispiel im pgf/tikz-Manual (Stichwort "dance around")

VG

MC3330
02-02-2020, 11:36
Perfekt, einmal mehr einen herzlichen Dank.

VG