我想要实现的是节点,我可以在左上角放置一个小索引,并在中间放置一行或两行描述。节点应该都具有相同的大小。我受以下启发实现了这是:
\documentclass{article}
\usepackage{tikz}
\usepackage{setspace}
\tikzstyle{WorkPackage} = [
rectangle,
rounded corners,
draw=black,
very thick,
minimum width = 12em,
minimum height=4.1em,
text width=10em,
node distance=0.5cm]
\newcommand{\CommonElementTextFormat}[2]
{
\begin{minipage}{10em}
\begin{spacing}{0.1}
\centering
{\hspace{-10.5em} \footnotesize #1 \hfill}%
\linebreak
{#2}
\linebreak
{\footnotesize \vspace{.6em}}
\end{spacing}
\end{minipage}
}
当我现在创建两个节点时,一个节点只有单行,另一个节点有多行描述,索引就乱了:
\begin{document}
\begin{tikzpicture}
\node[WorkPackage] {\CommonElementTextFormat{1)}{Image Acquisition \& Camera Calibration}};
\end{tikzpicture}
\begin{tikzpicture}
\node[WorkPackage] {\CommonElementTextFormat{1)}{Image Acquisition}};
\end{tikzpicture}
\end{document}
编辑:我选择减小间距,因为否则巨大节点内的单行描述似乎有点丢失。
答案1
\documentclass{article}
\usepackage{tikz}
\usepackage{setspace}
\tikzstyle{WorkPackage} = [
rectangle,
rounded corners,
draw=black,
very thick,
% minimum width = 12em,
% minimum height=4.1em,
% text width=10em,
node distance=0.5cm]
% \parbox allows you to specify the height as well as the width
% Placing a 1em margin or both sides of the parbox gives the
% left shifted index somewhere to go.
\newcommand{\CommonElementTextFormat}[2]% #1=index, #2=text
{\raisebox{16pt}{\makebox[1em][l]{\footnotesize #1}}%
\parbox[c][4em]{10em}{\footnotesize%
\vfil\centering{#2}\vfil
}\hspace*{1em}}
\begin{document}
\begin{tikzpicture}
\node[WorkPackage] {\CommonElementTextFormat{1)}{Image Acquisition \& Camera Calibration}};
\end{tikzpicture}
%
\begin{tikzpicture}
\node[WorkPackage] {\CommonElementTextFormat{1)}{Image Acquisition}};
\end{tikzpicture}
\begin{tikzpicture}
\node[WorkPackage] {\CommonElementTextFormat{1)}{A three line footnote that goes on and on and on and on}};
\end{tikzpicture}
%
\begin{tikzpicture}
\node[WorkPackage] {\CommonElementTextFormat{1)}{A four line footnote that goes on and on
and on and on and on and on and on and on}};
\end{tikzpicture}
\end{document}
答案2
我只会使用 TikZ 来放置该数字。
代码
\documentclass[varwidth]{standalone}
\usepackage{tikz,setspace}
\tikzset{WorkPackage/.style={
shape=rectangle, rounded corners, draw=black, very thick, text width=+10em,
align=center, inner xsep=+1em, minimum height=+4.1em, font=\setstretch{.1},
append after command={
\pgfextra{\footnotesize} node[anchor=north west] at (\tikzlastnode.north west) {#1}}}}
\newcommand*\WorkPackage[3][]{\tikz[#1]\node[WorkPackage={#2}]{#3};}
\begin{document}
\WorkPackage{1)}{Image Acquisition \& Camera Calibration}
\WorkPackage{2)}{Image Acquisition}
\WorkPackage{3)}{A three line footnote that goes on and on and on and on}
\WorkPackage{4)}
{A four line footnote that goes on and on and on and on and on and on and on and on}
\end{document}