我想用 TikZ 画出我的论文结构。在 Paint 中画出草图:
到目前为止,节点都很简单,但我找不到一个好的带有标签的分界线的解决方案。例如,我设法将一个名为“Preliminaries”的节点放置在“Introduction”节点上方,并在左侧任意距离放置,使用let
来自的解决方案这个问题,并想到用它的西北锚点画一条线。但我不知道如何确保这条线至少和图片一样宽(由章节节点最宽行的宽度决定),也不知道如何计算这条线的端点,以便它从第一个章节节点的中心向左和向右延伸相同的距离。
如何获取节点之间的水平分隔线,延伸至图形的整个宽度?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
chapter/.style={
rectangle,
minimum width=8mm,
minimum height=3mm,
rounded corners=1mm,
align=center,
draw
},
font=\sffamily
]
\node [chapter](introduction){
\textbf{Introduction} \\
Motivation, goals and contribution
};
\node [chapter, below=4mm of introduction.south](background){
\textbf{Background} \\
Context and terms
};
% This tries to make ``Preliminaries'' a node, but maybe this is not the best approach anyway
%\draw ($(introduction.north west)+(-1,0.5)$) -- ($(introduction.north east)+(1,0.5)$);
%\path let \p1 = (introduction.north) in node (preliminaries) at (-5, \y1+10) {
% Preliminaries
%};
\end{tikzpicture}
\caption{Structure of the thesis}
\label{fig:structure-of-the-thesis}
\end{figure}
\end{document}
答案1
像这样?
我在上面的图片中考虑你的(相当简单的)图像:
\documentclass{article}
\usepackage[showframe,% only for test page layout
margin=30mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{positioning, calc, shadows}
\begin{document}
\begin{figure}%[ht]
\centering
\begin{tikzpicture}[
node distance = 7mm and 4mm,
every node/.style = {font=\bfseries\itshape},
chapter/.style = {rectangle, draw, semithick, rounded corners,
text width=44mm, minimum height=11mm, align=center,
fill=white, drop shadow},
ys/.style = {yshift=-7mm}
]
\draw[thick] (0,0) coordinate (A1)
node[below right] {Preliminaries}
-- + (\textwidth,0)
coordinate (B1);
\node (ch1) [chapter, below=of $(A1)!0.5!(B1)$] {Introduction};
\node (ch2) [chapter, below=of ch1] {Background};
\draw[thick] ([ys] A1 |- ch2.south) coordinate (A2)
node[below right] {Problem states}
-- + (\textwidth,0)
coordinate (B2);
\node (ch3) [chapter, below left=of $(A2)!0.5!(B2)$] {State of the Art};
\node (ch4) [chapter, below right=of $(A2)!0.5!(B2)$] {Building of Theory};
\draw[thick] ([ys] A1 |- ch3.south) coordinate (A3)
node[below right] {Solution}
-- + (\textwidth,0)
coordinate (B3);
\node (ch5) [chapter, below=of $(A3)!0.5!(B3)$] {My New Theory};
\node (ch6) [chapter, below=of ch5] {Validation of the Method};
\draw[thick] ([ys] A1 |- ch6.south) coordinate (A4)
node[below right] {Conclusion}
-- + (\textwidth,0)
coordinate (B4);
\node (ch7) [chapter, below=of $(A4)!0.5!(B4)$] {Discussion and conclusions};
\node (ap1) [chapter, below left=of ch7] {Appendix A};
\node (ap2) [chapter, below =of ch7] {Appendix B};
\node (ap3) [chapter, below right=of ch7] {Appendix C};
\end{tikzpicture}
\caption{Structure of the thesis}
\label{fig:structure-of-the-thesis}
\end{figure}
\end{document}
答案2
如果您首先绘制所有框,则可以用来current bounding box
获取图形的左边框和右边框。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[
TestBox/.style={draw,minimum width=3cm,minimum height=3em,rounded corners=2mm}]
\node[TestBox] (A) {A};
\node[TestBox,below left= of A](B){B};
\node[TestBox,below right= of A](C){C is a bit longer than the other boxes};
\node[TestBox,below=of $(B.south east)!0.5!(C.south west)$](D) {D};
\node[TestBox,below=of D](E) {E};
%%
\coordinate(BBw) at ($(current bounding box.west)+(-5mm,0)$);
\coordinate(BBe) at ($(current bounding box.east)+(5mm,0)$);
\coordinate(Level1) at ($(C.south)!0.5!(D.north)$);
\draw (Level1 -| BBw) -- (Level1-|BBe) node[pos=0,anchor=north west]{Label of line};
\end{tikzpicture}
\end{document}