如何在 tikz 中格式化节点/结构?

如何在 tikz 中格式化节点/结构?

我已完成以下艾森豪威尔广场(或矩阵)受到此启发很棒的答案

艾森豪威尔广场

我希望我的空间效率更高:更小的文本尺寸/复选框、更薄的边框、方块之间没有空格/边距/装订线、方块内没有水平线等。
左侧的文本很好地近似了检查清单项文本的最大尺寸。

但经过大量的修改后,我仍然无法改变以下属性:

  1. 边界
    • 使边框超薄(1 像素就足够了)
  2. 核对清单项目/框
    • 删除水平线
    • \Box使每个清单项目的检查变得更小和/或用文字缩放
    • 使物品在垂直方向上更紧密/更靠近在一起?
  3. label文本
    • 在各个方块的左边缘/上边缘居中对齐

以下是我的文件:

main.tex

\documentclass[english]{book}

\usepackage{amssymb, tikz}
\usetikzlibrary{shapes.multipart, positioning, fit, backgrounds}

...

% \eisenbox: for making each box of an Eisenhower square
\newcommand{\eisenbox}[6][] {
    \node [rectangle split,rectangle split parts={#6}, fill=white,
    text width=5.25cm,align=left,text=#2,draw,sharp corners,draw=#2,
    #1]
    (multi-#3)
    {\strut$\Box$\nodepart{two}\strut$\Box$\nodepart{three}\strut$\Box$\nodepart{four}\strut$\Box$
    \nodepart{five}\strut$\Box$\nodepart{six}\strut$\Box$\nodepart{seven}\strut$\Box$
    \nodepart{eight}\strut$\Box$\nodepart{nine}\strut$\Box$\nodepart{ten}\strut$\Box$};
    \node[left=1pt of multi-#3.south west,anchor=south west,rotate=90,text=black] 
    (label-#3) {#5};
    
    \begin{scope}[on background layer]
        \node[fit=(multi-#3),fill=#2,sharp corners,
        label={[text=#2,anchor=south west,font=\bfseries]above left:#4}] (fit-#3){};
    \end{scope}
}

% \eisensquare: creates a fancy Eisenhower square
\newcommand{\eisensquare}[1] {
    \eisenbox{black}{tl}{\footnotesize Urgent}{\footnotesize Important}{#1}
    \eisenbox[right=0.2cm of multi-tl]{black}{tr}{\footnotesize Not Urgent}{}{#1}
    \eisenbox[below=0.2cm of multi-tl]{black}{bl}{}{\footnotesize Not Important}{#1}
    \eisenbox[right=0.2cm of multi-bl]{black}{br}{}{}{#1}
}

...

\begin{document}
    \frontmatter

    \maketitle
    ...

    \mainmatter

    ...
    \subfile{./folder/subfile.tex}

    \backmatter

\end{document}

subfile.tex

\documentclass[../main.tex]{subfiles}

    \begin{document}

    ...
    
    \paragraph{Foo}\mbox{}\\    
        \begin{tikzpicture}[font=\sffamily]
            \eisensquare{7}
        \end{tikzpicture}
    
    ...

\end{document}

不确定我做错了什么 。无论我将、等放在何处,都会tikz忽略/引发错误。widthline width\node [options]\eisenbox

pgf我对/完全陌生tikz,因此非常感谢您的任何见解。

编辑 1 ------------

按照格诺特 示范答案我差不多明白了。剩下的就是修改每个“象限”的项目数量。如果不是因为我将在很长一段时间内每天都使用它,我通常不会这么挑剔。

当剩余行数>项目数时,如何制作空白/空行?

main.tex

\newcommand\eisenlabel[1]{{\footnotesize\sffamily#1}}

% arguments: 1st is total # lines, 2nd is # items
\newcommand{\eisenbox}[2]{\fbox{%
        \begin{tabular}{l}
            \multido{}{#1}{%
                \makebox[0.44\textwidth][l]{$\square$} %adding \\ here makes errors, but I believe its absence is FUBARing the table
            }
        \end{tabular}%
}}

% first argument: max lines, then items per quadrant starting with urgent+important
% could do this without 1st arg by determining largest value
% but not familiar enough with this so we'll just supply it manually (for now)
\newcommand{\eisensquare}[5] {%
    \fboxrule=0.1ex% <<< adjust line width
    \begin{tabular}{@{}r@{\hspace{0.3em}}c@{\hspace{-\fboxrule}}c@{}} % <<< adjust distance between rotated labels and box
        & \eisenlabel{urgent} & \eisenlabel{not urgent} \\
        \turnbox{90}{\makebox[0pt]{\eisenlabel{important}}}
        & \eisenbox{#1}{#2} & \eisenbox{#1}{#3} \\[-\fboxrule] 
        \turnbox{90}{\makebox[0pt]{\eisenlabel{not important}}}
        & \eisenbox{#1}{#4} & \eisenbox{#1}{#5}
    \end{tabular}%
}

subfile.tex

\(\eisensquare{5}{3}{4}{5}{3}\)

答案1

这是一个灵活的解决方案。由于\multido在 中效果不佳tabular,我使用了更多基本命令。顶级命令是

\eisensquare{height of single box}{width of single box}{top left}{top right}{bottom left}{bottom right}

height并且width可以是绝对尺寸或长度的倍数,如\baselineskip(线的高度)或\textwidth

在此处输入图片描述

\documentclass{article}
\usepackage{amssymb,rotating,multido}
% \eisenlabel{width}{label}
\newcommand\eisenlabel[2]{\makebox[#1]{\footnotesize\sffamily#2}}
% \veisenlabel{height}{label}
\newcommand\veisenlabel[2]{\turnbox{90}{\eisenlabel{#1}{#2}}\ }
% \eisenbox{height}{width}{number of items}
\newcommand\eisenbox[3]{\fbox{%
  \vbox to #1{%
    \multido{}{#3}{\hbox to #2{$\square$\hfill}}%
    \vfill  
  }%
}}
% \eisensquare{height of single box}{width of single box}{top left}{top right}{bottom left}{bottom right}
\newcommand\eisensquare[6]{{%
  \fboxrule=0.1ex%
  \vbox{%
    \hbox{\ \eisenlabel{#2}{urgent}\ \eisenlabel{#2}{not urgent}}%
    \hbox{\veisenlabel{#1}{important}\eisenbox{#1}{#2}{#3}\hspace{-\fboxrule}\eisenbox{#1}{#2}{#4}}%
    \nointerlineskip
    \vspace{-\fboxrule}%
    \hbox{\veisenlabel{#1}{not important}\eisenbox{#1}{#2}{#5}\hspace{-\fboxrule}\eisenbox{#1}{#2}{#6}}%
}}}
\begin{document}
\noindent
\eisensquare{5\baselineskip}{0.4\textwidth}{3}{4}{5}{3}

\noindent
\eisensquare{2cm}{5cm}{3}{4}{5}{3}
\end{document}

答案2

Tikz 是一个很棒的包,但对于这种简单的设计,我建议使用表格。修改外观的位置可能更明显。

在此处输入图片描述

我建议使用emex作为长度单位,因为它们会随着字体大小而变化。在代码中,我标记了需要调整框的宽度、线宽和垂直标签距离的地方。

\documentclass{article}
\usepackage{amssymb,rotating}
\newcommand\eisenlabel[1]{{\footnotesize\sffamily#1}}
\newcommand\eisenline{\makebox[0.44\textwidth][l]{$\square$}}% <<< adjust width of boxes
\newcommand\eisenbox{\fbox{%
  \begin{tabular}{l}
    \eisenline\\
    \eisenline\\
    \eisenline\\
    \eisenline\\
    \eisenline\\
    \eisenline\\
    \eisenline
  \end{tabular}%
}}
\newcommand\eisensquare{{%
  \fboxrule=0.1ex% <<< adjust line width
  \begin{tabular}{@{}r@{\hspace{0.3em}}c@{\hspace{-\fboxrule}}c@{}} % <<< adjust distance between rotated labels and box
    & \eisenlabel{urgent} & \eisenlabel{not urgent} \\
  \turnbox{90}{\makebox[0pt]{\eisenlabel{important}}}
    & \eisenbox & \eisenbox \\[-\fboxrule] 
  \turnbox{90}{\makebox[0pt]{\eisenlabel{not important}}}
    & \eisenbox & \eisenbox
  \end{tabular}%
}}
\begin{document}
\noindent
\eisensquare
\end{document}

相关内容