2

How do I add a single row-column tikz table field say in the middle above A2 and A3 which combines both right columns?

\documentclass[12pt,twoside]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings,arrows,decorations.markings,decorations.pathmorphing}
\tikzset{
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center,
                        text width=10em,
                        fill=gray!10,
                   },
                        %baseline={([yshift=-0.5ex]current bounding box.center)},
        %minimum height=1.0em,
        %text depth=0.2em,
        %text height=0.8em,
                %text centered,
        nodes in empty cells,
                row 1/.style={nodes={fill=black, text=white, font=\bfseries}},
                row 2/.style={nodes={text height=3.3ex}},
            }
        }


\begin{document}

Hello World...
\begin{table}
\centering
\begin{tikzpicture}
\matrix[table, ampersand replacement=\&] (TabA1)
{
A1 \& A2 \& A3 \\
B1 \& $10^{2^{3^{4^{5}}}}$ \& B3 \\
};
\end{tikzpicture}
\caption{Glossary}
\label{tabA1}
\end{table}


\end{document}
  • You've asked 15 questions so far and not accepted any of the answers. May I ask why? – user121799 Jul 2 '18 at 15:15
  • 15 questions? What do you mean by accept? – Diger Jul 2 '18 at 15:24
  • If one looks at your profile one sees that you've asked 15 questions so far. none of their answers is accepted. You can accept an answer to your question by clicking on the check mark left of it. In addition you may consider upvoting an answer by clicking on the uparrow left of it. – user121799 Jul 2 '18 at 15:29
  • 1
    Just Like that? – Diger Jul 2 '18 at 20:21
1

One possibility is to use fit for that.

\documentclass[12pt,twoside]{report}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{tikz}
\usetikzlibrary{matrix,shadings,arrows,decorations.markings,decorations.pathmorphing,fit}
\tikzset{
    table/.style={
        matrix of nodes,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={
            rectangle,
            draw=black,
            align=center,
                        text width=10em,
                        fill=gray!10,
                   },
                        %baseline={([yshift=-0.5ex]current bounding box.center)},
        %minimum height=1.0em,
        %text depth=0.2em,
        %text height=0.8em,
                %text centered,
        nodes in empty cells,
                row 1/.style={nodes={fill=black, text=white, font=\bfseries}},
                row 2/.style={nodes={text height=3.3ex}},
            }
        }


\begin{document}

Hello World...
\begin{table}
\centering
\begin{tikzpicture}
\matrix[table, ampersand replacement=\&] (TabA1)
{
A1 \& A2 \& A3 \\
B1 \& $10^{2^{3^{4^{5}}}}$ \& B3 \\
};
\node[fit=(TabA1-1-2) (TabA1-1-3),yshift=16pt,draw,inner sep=-\pgflinewidth/2,
minimum height=24pt]{I fit two nodes};
\end{tikzpicture}
\caption{Glossary}
\label{tabA1}
\end{table}

\end{document}

enter image description here

  • Hey, what is the pgflinewidth/2 for? – Diger Jul 2 '18 at 13:55
  • But I'm using pgflinewidth*1 in the definitions. Why now dividing by 2 ? Shouldn't it be 1? – Diger Jul 2 '18 at 14:03
  • I know I noticed. I was just saying that I'm surprised because the original definition was *1 and not *1/2 – Diger Jul 2 '18 at 14:08
  • @Diger Setting column sep and row sep to -\pgflinewidth will just make TikZ draw the boundaries on top of each other. Setting inner sep to -\pgflinewidth/2 makes sure that the outer edge of the box coincides with the outer ends of the node(s) that it fits. – user121799 Jul 2 '18 at 14:11
  • So setting column sep and row sep e.g. to 2 separates the boundaries by how much pt? – Diger Jul 2 '18 at 14:30

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.