4

Is it possible to use circuitikz-shapes as cells inside a TikZ-matrix?
(I mean, as cells <*> & <*> & <*> ... \\, how to place nodes afterwards is already clear.)

If I put in |[tgenericshape]|{} I get an error ! Package PGF Math Error: Unknown function base (in 'base').

enter image description here

\documentclass[margin=5pt, multi=circuitikz]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{circuitikz}[]
\node[tgenericshape, label=center:GS0](G0){};

\matrix[matrix of nodes, nodes in empty cells, 
draw, column sep=11mm,
] at (0,-2) (m){
1 & 2 & 3 \\
%|[tgenericshape, label=center:GS1]|{} & |[fill=pink]|{Test} & \\ does not work
};
\end{circuitikz}
\end{document}

2 Answers 2

6

When you use the matrix of nodes option, it appears that TikZ automatically attempts to align the nodes within the cells along their text "baseline" (using anchor=base). However, the base anchor is not defined for certain circuitikz components (including tgenericshape). Consequently, an error occurs when TikZ tries to access this non-existent anchor for alignment.

To fix this, you simply need to override the alignment anchor for these cells (or for the entire matrix) by setting, for example, anchor=center. In the code below, I have applied this to the whole matrix.

\documentclass[margin=25pt, multi=circuitikz]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{circuitikz}[]
\node[tgenericshape, label=center:GS0](G0){};

\matrix[
        matrix of nodes, 
        nodes in empty cells, 
        draw, 
        column sep=11mm,
        row sep=5mm, % I added a little spacing between the rows for clarity        
        nodes={anchor=center} 
    ] at (0,-2) (m){
        1 & 2 & 3 \\        
        |[tgenericshape]|{} & |[fill=pink]|{Test} & |[oscillator]|{}\\
    };
    
\end{circuitikz}

\end{document}

enter image description here

Note:
While anchor=center solves the error, it also changes how regular text is aligned. They will now be aligned by their geometric center rather than the text baseline. If you need perfect alignment when mixing text with components, you might need to make small manual adjustments to the row heights.

4

This is basically @kabenyuk's answer (so by all means, if you upvote my answer you have to upvote that other answer as well!), just with a \strut added to every node such that even with center-anchoring you get text correctly aligned (it will however enlarge the nodes a bit).

\documentclass[margin=25pt, multi=circuitikz]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{circuitikz}[]
\node[tgenericshape, label=center:GS0](G0){};

\matrix[
        matrix of nodes,
        nodes in empty cells,
        draw,
        column sep=11mm,
        row sep=5mm, % I added a little spacing between the rows for clarity
        nodes={execute at end node=\strut, anchor=center},
    ] at (0,-2) (m){
      1 & 2 & 3 & pqy \\
        |[tgenericshape]|{} & |[fill=pink]|{Test} & |[oscillator]|{}\\
    };

\end{circuitikz}

\end{document}

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.