我有一个完整的页面,我设法用 缩小了它\resizebox
。不幸的是,在 MWE 中发现这个问题后,我将其放回我的文档中,标题现在位于页脚中...
我该如何解释调整大小框中的标题或将标题包含在调整大小框中?
梅威瑟:
\documentclass{article}
\usepackage[letterpaper, margin=0.5in, includefoot]{geometry} % Advanced page geometry configuation
\usepackage{fancyhdr} % Used for header and footer creation
\pagestyle{fancy}
\fancyhf{} % clear all fields
\lfoot{Lorem\\Ipsum}\cfoot{dolor sit\\amet \\ \thepage}\rfoot{Rev. \#\\ \today}
\usepackage{tikz} % Flowcharts
\renewcommand{\headrulewidth}{0.0pt} % removes line at top that comes w/ fancyhdr
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc, matrix}
% Define block styles
\tikzstyle{state} = [ rounded rectangle,
draw,
text centered,
minimum height = 3em,
minimum width = 6em,
inner sep = 5pt
]
\tikzstyle{test} = [ diamond,
draw,
shape aspect = 2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action} = [ rectangle, draw,
text width = 8em,
inner sep = 5pt,
minimum height = 5em
]
\tikzstyle{data} = [ trapezium,
draw,
trapezium left angle = 60,
trapezium right angle = 120pt,
minimum height = 6em,
text width = 5em,
inner xsep = 0pt
]
\tikzstyle{line} = [ draw, -triangle 45 ]
\begin{document}
\begin{figure}[H]
\begin{center}
\resizebox{\textwidth}{\textheight}{%
\input{./flowchart.tex}
}
\caption{\textbf {My Stupid Flowchart} }
\end{center}
\end{figure}
\end{document}
流程图.tex:
\resizebox{\textwidth}{\textheight}{%
\begin{tikzpicture}[align = flush center, font = \small]
% Place nodes
\matrix [matrix of nodes, column sep = 0.5em, row sep = 1.3em,
draw, dotted,
nodes={solid},
matrix anchor=south east,
inner sep = 1em,
ampersand replacement=\&
] (state-mtrx) at (0,0)
{
|[data] (a)| Lorem ipsum dolor sit amet, c \\
|[test] (b)| Lorem ipsum d \\
|[action] (c)| Lorem ipsum dolor sit amet, consectetur adipiscing\\
|[test] (d)| Lorem ipsum dolor \\
|[action] (e)| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus nisl id \\
|[test] (f)| Lorem ipsum dolor sit amet, \\
|[action] (g)| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus nisl id lectus\\
|[action] (h)| Lorem ipsum dolor sit amet, consectetur adipiscing eli \\[1em]
|[action] (j)| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus nisl id \\
[1em]\\
};
\matrix [matrix of nodes, column sep = 0.5em, row sep = 1.3em,
nodes = {solid},
draw, dotted,
matrix anchor=south west,
inner xsep = 3em,
ampersand replacement=\&
] (state-send-response) at (0,0)
{
\\
\\
\\
\&|[test] (i)| Lorem ipsum dolor? \\
\&|[test] (k)| ILorem ipsum dolor sit amet,? \\
\&|[action] (l)| Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque \\ [1em]
\&|[data] (m)| Lorem ipsum dolor sit amet, consect \\
|[state] (n)| Lorem ipsum dolor sit
\&|[state] (p)| Lorem ipsum dolor\\
};
\node[state, above = of a] (write) {WLorem ipsu};
\path [] ([shift={(-3mm, 0)}]state-mtrx.north west) -- ([shift={(-3mm, 0)}]state-mtrx.south west) coordinate(state-line);
\path let \p1=(state-line), \p2=($ (a)!0.5!(b)$ ) in (\p2) -- node [left, very near end] {Lorem ipsum dolor} (\x1,\y2);
\path let \p1=(state-line), \p2=($ (c)!0.5!(d)$ ) in (\p2) -- node [left, very near end] {Lorem ipsum dolor sit am} (\x1,\y2);
\path let \p1=(state-line), \p2=($ (e)!0.5!(f)$ ) in (\p2) -- node [left, very near end] {Lorem ipsum dol} (\x1,\y2);
\path let \p1=(state-line), \p2=(g) in (\p2) -- node [left, very near end] {Lorem ipsum dolor} (\x1,\y2);
\path let \p1=(state-line), \p2=(h) in (\p2) -- node [left, very near end] {Lorem ipsum dolo\\Lorem ipsum dol} (\x1,\y2);
\path let \p1=(state-line), \p2=(j) in (\p2) -- node [left, very near end] {Lorem ipsum dolo} (\x1,\y2);
\node [above = 0em of state-send-response.north] {Lorem ipsum dolor s};
% Draw edges
% Dotted separators
\path [draw, dotted] let \p1=( $(b.south)!0.5!(c.north)$ ), \p2=(state-mtrx.north west), \p3=(state-mtrx.north east) in (\x2, \y1) -- (\x3, \y1);
\path [draw, dotted] let \p1=( $(d.south)!0.5!(e.north)$ ), \p2=(state-mtrx.north west), \p3=(state-mtrx.north east) in (\x2, \y1) -- (\x3, \y1);
\path [draw, dotted] let \p1=( $(f.south)!0.5!(g.north)$ ), \p2=(state-mtrx.north west), \p3=(state-mtrx.north east) in (\x2, \y1) -- (\x3, \y1);
\path [draw, dotted] let \p1=( $(g.south)!0.5!(h.north)$ ), \p2=(state-mtrx.north west), \p3=(state-mtrx.north east) in (\x2, \y1) -- (\x3, \y1);
\path [draw, dotted] let \p1=( $(h.south)!0.3!(j.north)$ ), \p2=(state-mtrx.north west), \p3=(state-mtrx.north east) in (\x2, \y1) -- (\x3, \y1);
% left State Paths
\path [line] (write) -- (a);
\path [line] (a) -- (b);
%% (d) paths - not in order because of reference point (d-no)
\path [line] (d) -- node [right, near start] {Yes} (e);
\path [line] (d.east) -- node [above, near start] {No} +(1.5,0)coordinate(d-no) -| (i);
\path [line] (b) -- node [right, very near start] {Yes} (c);
\path [line] (b) -| node [above, pos=0.02] {No} (d-no);
\path [line] (c) -- (d);
\path [line] (e) -- (f);
\path [line] let \p1=([shift={(2mm, 0)}]state-mtrx.west), \p2=(f.west) in (\p2) -- node [above, near start] {Yes} (\x1, \y2) |- ( $(h.south)!0.5!(j.north)$ );
\path [line] (f) -- node [right, near start] {No} (g);
\path [] (b.east) -- +(1,0)coordinate(copy-no);
\path [line] (j.south) |- ([shift={(2mm, 2em)}]state-mtrx.south east) -| (d-no);
\path [line] (g) -- (h);
\path [line] (h) -- (j);
% Response State paths
\path [line] (i.east) -- node [above, near start] {Yes} +(1,0) |- ( $(l.south)!0.3!(m.north)$ );
\path [line] (i.south) -- node [right] {No} (k);
\path [line] (k) -- node [right] {Yes} (l);
\path [line] (k.west) -| node [above, very near start] {No} (n);
\path [line] (l) -- (m);
\path [line] (m) -- (p);
\end{tikzpicture}
}
答案1
\resizebox
以下方法将标题放在一个框内并测量其高度。然后可以计算出高度的值。
在 中,
flowchart
我删除了额外的\resizebox
。我还注释了 之后的行尾\end{tikzpicture}
。我们处于水平模式,这意味着空间会影响宽度。\input{./flowchart.tex}
出于同样的原因,我还删除了 之后的空格。我已经
showframe
为包添加了geometry
显示文本主体边框的选项。\resizebox
不太准确。因此我把图中的内容包裹在附加内容中,\vbox
并在其中进行了小幅修正。\hspace{-0.3333em}
取消inner sep
最左边的文本节点。
更新:我已将其移动到文件flowchart.tex
,因为它是流程图的一个属性。只需在之前添加以下行\begin{tikzpicture}
:\hspace*{-.3333em}% remove left `inner sep` from the leftmost text node
\nointerlineskip
防止图片框和标题框之间出现额外的粘合。更新:仅当流程图超出可用宽度或高度时才会缩放。
示例文件:
\documentclass{article}
\usepackage[showframe,letterpaper, margin=0.5in, includefoot]{geometry} % Advanced page geometry configuation
\usepackage{fancyhdr} % Used for header and footer creation
\pagestyle{fancy}
\fancyhf{} % clear all fields
\lfoot{Lorem\\Ipsum}\cfoot{dolor sit\\amet \\ \thepage}\rfoot{Rev. \#\\ \today}
\usepackage{tikz} % Flowcharts
\renewcommand{\headrulewidth}{0.0pt} % removes line at top that comes w/ fancyhdr
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc, matrix}
% Define block styles
\tikzstyle{state} = [ rounded rectangle,
draw,
text centered,
minimum height = 3em,
minimum width = 6em,
inner sep = 5pt
]
\tikzstyle{test} = [ diamond,
draw,
shape aspect = 2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action} = [ rectangle, draw,
text width = 8em,
inner sep = 5pt,
minimum height = 5em
]
\tikzstyle{data} = [ trapezium,
draw,
trapezium left angle = 60,
trapezium right angle = 120pt,
minimum height = 6em,
text width = 5em,
inner xsep = 0pt
]
\tikzstyle{line} = [ draw, -triangle 45 ]
\newsavebox\captionbox
\newsavebox\flowchartbox
\newdimen\flowchartmaxheight
\newcommand*{\maxminipageheight}{%
\dimexpr\ifdim\height>\textheight\textheight\else\height\fi\relax
}
\begin{document}
\begin{figure}
\begin{minipage}[b][\maxminipageheight][c]{\textwidth}%
\sbox\captionbox{%
\parbox[b]{\textwidth}{%
\centering
\caption{\textbf {My Stupid Flowchart}}%
}%
}%
\sbox\flowchartbox{\input{flowchart}}%
\pgfmathsetlength{\flowchartmaxheight}{\textheight-\ht\captionbox}%
\ifdim\ht\flowchartbox>\flowchartmaxheight
\sbox\flowchartbox{%
\resizebox{!}{\flowchartmaxheight}{\box\flowchartbox}%
}%
\fi
\ifdim\wd\flowchartbox>\textwidth
\sbox\flowchartbox{%
\resizebox{\textwidth}{!}{\box\flowchartbox}%
}%
\fi
\centerline{\box\flowchartbox}%
\vspace{0pt minus .5pt}% fix for rounding errors in \resizebox
\nointerlineskip
\centerline{\box\captionbox}%
\end{minipage}%
\end{figure}
\end{document}
测量位置
第二种方法使用包zref-abspage
来测量首先写入.aux
文件的位置。在第二次运行中,将知道并使用正确的位置。
更新:这个例子不是已更新有关缩放行为的内容。
\documentclass{article}
\usepackage[showframe,letterpaper, margin=0.5in, includefoot]{geometry} % Advanced page geometry configuation
\usepackage{fancyhdr} % Used for header and footer creation
\pagestyle{fancy}
\fancyhf{} % clear all fields
\lfoot{Lorem\\Ipsum}\cfoot{dolor sit\\amet \\ \thepage}\rfoot{Rev. \#\\ \today}
\usepackage{tikz} % Flowcharts
\renewcommand{\headrulewidth}{0.0pt} % removes line at top that comes w/ fancyhdr
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes, arrows, positioning, calc, matrix}
% Define block styles
\tikzstyle{state} = [ rounded rectangle,
draw,
text centered,
minimum height = 3em,
minimum width = 6em,
inner sep = 5pt
]
\tikzstyle{test} = [ diamond,
draw,
shape aspect = 2,
inner sep = 0pt,
text width = 7em,
text centered
]
\tikzstyle{action} = [ rectangle, draw,
text width = 8em,
inner sep = 5pt,
minimum height = 5em
]
\tikzstyle{data} = [ trapezium,
draw,
trapezium left angle = 60,
trapezium right angle = 120pt,
minimum height = 6em,
text width = 5em,
inner xsep = 0pt
]
\tikzstyle{line} = [ draw, -triangle 45 ]
\usepackage{zref-savepos}
\providecommand*{\zsaveposy}{\zsavepos}% support older zref-savepos
\newdimen\flowheight
\begin{document}
\begin{figure}
\vbox to \textheight{%
\centering
\makeatletter
\zsaveposy{flow-beg}%
\zref@refused{flow-beg}%
\setlength{\flowheight}{-\dimexpr\zposy{flow-end}sp-\zposy{flow-beg}sp\relax}%
\resizebox{\textwidth}{%
\ifdim\flowheight>0pt \flowheight\else .75\textheight\fi
}{%
\input{flowchart}%
}\par
\vss
\nointerlineskip
\zsaveposy{flow-end}%
\caption{\textbf {My Stupid Flowchart}}%
}
\end{figure}
\end{document}