如何在 tikz 中格式化節點/結構?

如何在 tikz 中格式化節點/結構?

我做了以下艾森豪威爾方陣(或稱矩陣)受此啟發很棒的答案:

艾森豪威爾廣場

我希望我的文字更節省空間:更小的文字大小/複選框、更薄的邊框、正方形之間沒有空間/邊距/裝訂線、正方形內沒有水平線等
。良好近似值。尺寸檢查清單項目文字應為。

但經過大量修改後,我仍然無法更改以下屬性:

  1. 邊框
    • 讓邊框超薄(1 px 就足夠了)
  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在 a 中效果不佳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}

相關內容