
저는 꽤 익숙하기 tikz
때문에 기본 사항을 이해합니다. 그러나 구문과 같은 절차를 만드는 가장 좋은 방법이 무엇인지 정말 혼란스럽습니다. 메커니즘이 너무 많아서 어느 것이 가장 좋은지 알 수 없습니다.
제가 그린 예시 그림은 다음과 같습니다. 코드를 더 간결하고 유지 관리하기 쉽게 만들기 위해 LaTeX를 알아낼 수 있지만 어떤 구성이 가장 좋은지 잘 모르겠습니다.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\begin{document}
\tikzset{%
body/.style={inner sep=0pt,outer sep=0pt,shape=rectangle,draw,ultra thick,minimum height=0.5cm,anchor=south west},
dimen/.style={<->,>=latex,thin,
every rectangle node/.style={fill=white,midway}},
symmetry/.style={dashed,thin},
}
\begin{tikzpicture}[array/.style={
rectangle split,
rectangle split horizontal,
rectangle split parts=#1,
thick,draw,
anchor=center,
}]]
\node [array=10, align=center,,minimum width=\textwidth] at (0,0) (pool) {
\nodepart{one} \rotatebox{-90}{\begin{tabular}{ll}\textbf{\texttt{struct}}\\\texttt{Cons}\end{tabular}}
\nodepart{two} \rotatebox{-90}{\begin{tabular}{ll}\textbf{\texttt{struct}}\\\texttt{Cons}\end{tabular}}
\nodepart{three} $\cdots\cdots\cdots$
\nodepart{four} \rotatebox{-90}{\begin{tabular}{ll}\textbf{\texttt{struct}}\\\texttt{Cons}\end{tabular}}
\nodepart{five} $\cdots\cdots\cdots$
\nodepart{six} \rotatebox{-90}{\begin{tabular}{ll}\textbf{\texttt{struct}}\\\texttt{Cons}\end{tabular}}
\nodepart{seven} $\cdots\cdots\cdots$
\nodepart{eight} \rotatebox{-90}{\begin{tabular}{ll}\textbf{\texttt{struct}}\\\texttt{Cons}\end{tabular}}
\nodepart{nine} $\cdots\cdots\cdots$
\nodepart{ten} \rotatebox{-90}{\begin{tabular}{ll}\textbf{\texttt{struct}}\\\texttt{Cons}\end{tabular}}
};
\draw (pool.south west) -- ++(0,-1.5) coordinate (A1) -- ++(0,-5pt);
\draw (pool.south east) -- ++(0,-1.5) coordinate (A2) -- ++(0,-5pt);
\draw [dimen] (A1) -- (A2) node {$2^{\texttt{LG2\_POOLSIZE}} = 2^{14} = 16,384$};
\node (last) at (0,-1.5) {{\Large \emph{Pool of ``\textup{\texttt{\textbf{struct} Cons}}'' Records}}};
\node [body,minimum width=1cm] (last) at (-6,3.5) { \texttt{car} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.one north);
\node [body,minimum width=1cm] (last) at (-5,2) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.two north);
\node [body,minimum width=1cm] (last) at (-4,3.4) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[latex->] (last.south) -- (pool.four north);
\node [body,minimum width=1cm] (last) at (-2.5,3) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.six north);
\node [body,minimum width=1cm] (last) at (0,2.5) { \texttt{car} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.eight north);
\node [body,minimum width=1cm] (last) at (2,4) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.ten north);
\node [body,minimum width=1cm] (last) at (5,2.5) { \texttt{car} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.eight north);
\end{tikzpicture}
\end{document}
출력이 첨부됩니다. 네, 너무 예쁘지는 않다는 건 알지만 현 단계에서는 그게 제가 할 수 있는 일이에요.
내 질문은 다음과 같습니다. 위 코드를 단순화하기 위해 어떤 추상화 구성을 권장합니까? 보다 일반적으로 tikz/LaTeX 도구 상자에는 무엇이 있으며 언제 이러한 도구를 사용해야 합니까?
답변1
제 생각에는 귀하의 질문이 너무 모호하거나 광범위하지만 제 생각에 떠오르는 가능성은 다음과 같습니다.
scope
환경 사용스타일 사용, 사전 정의 또는 자체 정의
예를 들어 일곱 번 글을 쓰는 대신에 \node [body,minimum width=1cm]
글을 쓸 수도 있었습니다.
\begin{tikzpicture}
% …
\begin{scope}[every node/.style={body,minimum width=1cm}]% scope and pre-defined style
\node (last) at (-6,3.5) { \texttt{car} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.one north);
\node (last) at (-5,2) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.two north);
\node (last) at (-4,3.4) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[latex->] (last.south) -- (pool.four north);
\node (last) at (-2.5,3) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.six north);
\node (last) at (0,2.5) { \texttt{car} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.eight north);
\node (last) at (2,4) { \texttt{cdr} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.ten north);
\node (last) at (5,2.5) { \texttt{car} };
\draw (last.north west) -- ++(0,0.3) coordinate (A1) -- ++(0,5pt);
\draw (last.north east) -- ++(0,0.3) coordinate (A2) -- ++(0,5pt);
\draw [dimen] (A1) -- (A2) node {14b};
\draw[->] (last.south) -- (pool.eight north);
\end{scope}
\end{tikzpicture}
또는 다음을 사용하여 스타일을 정의할 수도 있습니다 \tikzset
.
\tikzset{bodynode/.style={body,minimum width=1cm}}% self-defined style
이미 를 사용했으므로 \tikzset
이를 다른 정의에 간단히 추가할 수 있습니다.
\begin{tikzpicture}
% …
\node[bodynode] (last) at (-6,3.5) { \texttt{car} };
% …
\node[bodynode] (last) at (-5,2) { \texttt{cdr} };
% …
\node[bodynode] (last) at (-4,3.4) { \texttt{cdr} };
% …
\node[bodynode] (last) at (-2.5,3) { \texttt{cdr} };
% …
\node[bodynode] (last) at (0,2.5) { \texttt{car} };
% …
\node[bodynode] (last) at (2,4) { \texttt{cdr} };
% …
\node[bodynode] (last) at (5,2.5) { \texttt{car} };
% …
\end{tikzpicture}
그리고 이들 모두를 조합하면 반복되는 bodynode
추가도 저장할 수 있습니다.
\tikzset{bodynode/.style={body,minimum width=1cm}}% self-defined style
\begin{tikzpicture}
% …
\begin{scope}[every node/.style=bodynode]% scope and pre-defined style calling
% self-defined style
\node (last) at (-6,3.5) { \texttt{car} };
% …
\node (last) at (-5,2) { \texttt{cdr} };
% …
\node (last) at (-4,3.4) { \texttt{cdr} };
% …
\node (last) at (-2.5,3) { \texttt{cdr} };
% …
\node (last) at (0,2.5) { \texttt{car} };
% …
\node (last) at (2,4) { \texttt{cdr} };
% …
\node (last) at (5,2.5) { \texttt{car} };
% …
\end{scope}
\end{tikzpicture}