5

I do have a tex, that always show me a twolines, in a tikzfigure when letter Q is in the line. Let me share the TEX with you

\documentclass[parskip]{scrartcl}
\usepackage[margin=10mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}

\begin{document}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

%\begin{center}
\begin{tikzpicture}
\matrix (magic) [matrix of nodes, style={font=\ttfamily}, nodes={minimum width=1.6cm,minimum 
 height=1.6cm, draw,thin},draw, row sep=-\pgflinewidth, column sep=-\pgflinewidth]
 { 
 D  &G  &W  &P  &V  &W  &N  &J  &A  &J  &V  &O\\  
 I  &E  &R  &E  &I  &K  &E  &Y  &M  &U  &N  &O\\  
 P  &L  &E  &N  &G  &B  &C  &R  &W  &J  &R  &A\\  
 K  &I  &C  &T  &O  &G  &F  &E  &B  &S  &O  &E\\  
 Y  &P  &T  &A  &W  &N  &O  &F  &Q  &X  &O  &U\\  
 C  &S  &A  &G  &C  &U  &A  &D  &R  &A  &D  &O\\  
 I  &E  &N  &O  &T  &J  &N  &N  &D  &N  &B  &K\\  
 R  &L  &G  &N  &Z  &O  &N  &C  &B  &E  &U  &N\\  
 C  &D  &U  &O  &P  &M  &Z  &Y  &X  &J  &D  &W\\  
 U  &A  &L  &U  &A  &B  &F  &E  &L  &O  &R  &T\\  
 L  &Q  &O  &T  &R  &I  &A  &N  &G  &U  &L  &O\\  
 O  &A  &U  &U  &N  &B  &I  &V  &B  &D  &U  &H\\  
 };
\end{tikzpicture}
%\end{center}

A buscar: 
\begin{itemize}
\item PENTAGONO
\item CUADRADO
\item CIRCULO
\item TRIANGULO
\item ELIPSE
\item RECTANGULO
\end{itemize}

\end{document}

When I do that. Always the lines with Q in the pdf show double lines. I browse around but have no hints on how to solve it.

There is a figure of the result in that line :

Near to the Q letter

Any help is really appreciated it.

JP

  • It is the descender in Q which is the issue. Replace Q with \smash{Q}\vphantom{X} and problem goes away. – Steven B. Segletes Apr 24 '20 at 0:23
6

You need to define nodes anchors, for example anchor=center:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{matrix}

\begin{document}
    \begin{tikzpicture}
\matrix (m) [matrix of nodes, 
             nodes = {draw,thin, minimum size=1.6cm, anchor=center},
             draw, 
             row sep=-\pgflinewidth, 
             column sep=-\pgflinewidth]
 {
 D  &G  &W  &P  &V  &W  &N  &J  &A  &J  &V  &O\\
 I  &E  &R  &E  &I  &K  &E  &Y  &M  &U  &N  &O\\
 P  &L  &E  &N  &G  &B  &C  &R  &W  &J  &R  &A\\
 K  &I  &C  &T  &O  &G  &F  &E  &B  &S  &O  &E\\
 Y  &P  &T  &A  &W  &N  &O  &F  &Q  &X  &O  &U\\
 C  &S  &A  &G  &C  &U  &A  &D  &R  &A  &D  &O\\
 I  &E  &N  &O  &T  &J  &N  &N  &D  &N  &B  &K\\
 R  &L  &G  &N  &Z  &O  &N  &C  &B  &E  &U  &N\\
 C  &D  &U  &O  &P  &M  &Z  &Y  &X  &J  &D  &W\\
 U  &A  &L  &U  &A  &B  &F  &E  &L  &O  &R  &T\\
 L  &Q  &O  &T  &R  &I  &A  &N  &G  &U  &L  &O\\
 O  &A  &U  &U  &N  &B  &I  &V  &B  &D  &U  &H\\
 };
    \end{tikzpicture}
\end{document}

enter image description here

  • Thanks! it works. Is it better to use an anchor that the option of text depth=0pt? – user111375 Apr 24 '20 at 0:49
6

As my comment indicated, the issue is the Q has depth that the other capital letters lack. To resolve this, you can set text depth=0pt. With such an approach, the baselines of the letters are uniformly preserved.

While not needed for this MWE, Schroedinger's cat points out that \usetikzlibrary{positioning} offers other similar options to text depth that may be useful in comparable problems.

\documentclass[parskip]{scrartcl}
\usepackage[margin=10mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}
\begin{document}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

%\begin{center}
\begin{tikzpicture}
\matrix (magic) [matrix of nodes, style={font=\ttfamily}, nodes={minimum width=1.6cm,minimum 
 height=1.6cm, text depth=0pt, draw,thin},draw, row sep=-\pgflinewidth, column sep=-\pgflinewidth]
 { 
 D  &G  &W  &P  &V  &W  &N  &J  &A  &J  &V  &O\\  
 I  &E  &R  &E  &I  &K  &E  &Y  &M  &U  &N  &O\\  
 P  &L  &E  &N  &G  &B  &C  &R  &W  &J  &R  &A\\  
 K  &I  &C  &T  &O  &G  &F  &E  &B  &S  &O  &E\\  
 Y  &P  &T  &A  &W  &N  &O  &F  &Q  &X  &O  &U\\  
 C  &S  &A  &G  &C  &U  &A  &D  &R  &A  &D  &O\\  
 I  &E  &N  &O  &T  &J  &N  &N  &D  &N  &B  &K\\  
 R  &L  &G  &N  &Z  &O  &N  &C  &B  &E  &U  &N\\  
 C  &D  &U  &O  &P  &M  &Z  &Y  &X  &J  &D  &W\\  
 U  &A  &L  &U  &A  &B  &F  &E  &L  &O  &R  &T\\  
 L  &Q  &O  &T  &R  &I  &A  &N  &G  &U  &L  &O\\  
 O  &A  &U  &U  &N  &B  &I  &V  &B  &D  &U  &H\\  
 };
\end{tikzpicture}
%\end{center}

A buscar: 
\begin{itemize}
\item PENTAGONO
\item CUADRADO
\item CIRCULO
\item TRIANGULO
\item ELIPSE
\item RECTANGULO
\end{itemize}

\end{document}

enter image description here

  • Thanks! it also works. Is it better to use a text depth that an anchor? – user111375 Apr 24 '20 at 0:49
  • @user111375 It's your preference, I would think. – Steven B. Segletes Apr 24 '20 at 0:50
  • 1
    @user111375 text depth is better, just look at the vertical position of Q in the other answer. This key does not require the positioning library, though. You should set the text depth, the text height and the anchor. – user194703 Apr 24 '20 at 1:11
  • 1
    @Schrödinger'scat Thanks for the clarification on library. I will edit. – Steven B. Segletes Apr 24 '20 at 1:16
  • 2
    The positioning library is in principle the right tool to address such problems, it has keys like base right and so on which are useful for aligning the baselines of characters/texts. So it is useful to mention it. – user194703 Apr 24 '20 at 1:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.