后续内容:带有表格、文本、背景颜色和外部图形注释的图形 [tikz]

后续内容:带有表格、文本、背景颜色和外部图形注释的图形 [tikz]

这是 带表的图形(使用带库矩阵的 tikz)

虽然我之前的问题得到了很好的答案和反馈(见上面的链接),但我很难对它做出一些改变;例如删除图中的一行和一列,同时调整标签和外部文本(带括号)的位置。

尝试了几次之后,我决定在这里寻求帮助。

我正在寻找这个:
Goal

我的代码如下[代码的最后几行带有注释,因为那是我没有理解正确的部分]:

    \documentclass[12pt,a4paper]{article}
    \usepackage[margin=1in]{geometry} 
    \usepackage{makecell}
    \usepackage{tikz} 
    \usetikzlibrary{trees, 
            calc, 
            matrix, 
            decorations.pathreplacing,
            calligraphy,
            positioning} 


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    \begin{document} 

    \begin{figure}[htbp!]
    \centering
    \footnotesize
    \caption{Levels of Policy Monitoring}
    \label{monitoring}
    \begin{tikzpicture}[
    node distance = 1mm and 3mm,
    BC/.style = {decorate,
    decoration={calligraphic brace, amplitude=3mm,
    raise=#1, mirror}, thick, pen colour={gray}},
                ]
    \matrix (m) [matrix of nodes,
         nodes={draw, minimum size=25mm, outer sep=0pt},
         column sep=-\pgflinewidth,
         row sep=-\pgflinewidth,
         colum 1/.style={font=\bfseries},
         row 1/.style={font=\bfseries},
         CB/.style = {fill=black!80, text=white},
         CG/.style = {fill=gray},
         CS/.style = {fill=gray!50}, 
         ]
    {       & {\makecell{President's \\ Party}}   & {\makecell{Party A}} \\
    {\textbf{\makecell{President's \\ Party}}}   & |[CS]| {\makecell{Within \\ Cabinet \\ Party}}   &  {\makecell{Among \\ Cabinet \\ Parties}}  \\
    { \textbf{\makecell{Party A}}}   &  {\makecell{Among \\ Cabinet \\ Parties}}   & |[CS]| {\makecell{Within \\ Cabinet \\ Party}}   \\
    {\textbf{\makecell{Party C}}}    &  {\makecell{From \\ Opposition \\ Party}}      &  {\makecell{From \\ Opposition \\ Party}}   \\
    };
    %\node[above=of m-1-3] {\textbf{Answering}};
    %\node[left =of m-3-1, rotate=90] {\textbf{Questioning}};
    %\draw[BC= 2mm, rotate=180] (m-4-4.south east) -- node[below= -10mm, sloped] {Cabinet Members} (m-1-4.north east);
    %\draw[BC=11mm, rotate=180] (m-5-4.south east) -- node[below=-19mm, sloped] {Legislative Parties} (m-1-4.north east);
    \end{tikzpicture}
    \end{figure}

    \end{document}

答案1

enter image description here

您的代码有很多错误:(i)您遗漏了对书法库的修复以及(ii)由于多行内容节点带来不必要的复杂性......为此您不需要\makecell宏,只需定义节点的文本宽度:

\documentclass[12pt,a4paper]{article}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
% temporary fix for calligraphy package <---
\usepackage{expl3}
\ExplSyntaxOn
\int_zero_new:N \g__prg_map_int
\ExplSyntaxOff
% end of temporary fix
\usetikzlibrary{calc,
                matrix,
                decorations.pathreplacing,
                calligraphy,
                positioning,
                trees}

\begin{document}
    \begin{figure}[htbp!]
\centering
\footnotesize
\caption{Levels of Policy Monitoring}
\label{monitoring}
\begin{tikzpicture}[
node distance = 1mm and 3mm,
    BC/.style = {decorate,
decoration={calligraphic brace, amplitude=3mm, raise=#1}, 
very thick, pen colour={gray}},
    BF/.style = {font=\bfseries},   % <---
    CB/.style = {fill=black!70, text=white},
    CG/.style = {fill=gray},
    CS/.style = {fill=gray!50},
            ]
\matrix (m) [matrix of nodes, 
     nodes={draw, minimum size=24mm, align=flush center, % <---
            text width =\pgfkeysvalueof{/pgf/minimum width}-2*\pgfkeysvalueof{/pgf/inner xsep}, % <---
            outer sep=0pt, anchor=south},
     column sep=-\pgflinewidth,
     row sep=-\pgflinewidth,
     colum 1/.style={font=\bfseries},
     row 1/.style={font=\bfseries},
     ]
{       & President's Party             & Party A                       \\
|[BF]| President's Party 
        & |[CS]| Within Cabinet Party   &  Among Cabinet Parties        \\
|[BF]| Party A
        &  Among Cabinet Parties        & |[CS]| Within Cabinet Party   \\
|[BF]| Party C
        &  |[CB]| From Opposition Party & |[CB]| From Opposition Party  \\
};
\node[BF, above=of m-1-2.north east] {Answering};
\node[BF, left =of m-3-1, rotate=90,anchor=south] {Questioning};
\draw[BC= 2mm] (m-1-3.north east) -- node[above= 5mm, sloped] {Cabinet Members} (m-3-3.south east);
\draw[BC=12mm] (m-1-3.north east) -- node[above=15mm, sloped] {Legislative Parties} (m-4-3.south east);
\end{tikzpicture}
    \end{figure}
\end{document}

相关内容