在我的文档中,我有一个巨大的数据流图,它正好是一页高。由于它不是很宽,我想把它放在一页的左侧/右侧,而将普通文本放在另一侧。
最直观的方法是使用wrapfig
,但此包总是将图形放在当前章节的最末尾。这有点奇怪,因为我可以通过将环境更改wrapfigure
为figure
图形确实适合一页的环境来验证。
以下是 MWE:
\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
decorations.pathreplacing,decorations.pathmorphing,shapes,
matrix,shapes.symbols}
\usepackage{wrapfig}
\def\n{3}
\newcommand{\bridgedblock}[1]{
% args 1: num featuremaps, 2: divide by two, 3: fill color, 4: name prefix
\node[normalnode] (#1-node1) {\scriptsize label1};
\begin{scope}[node distance=0.25cm]
\node[normalnode] (#1-node2) {\scriptsize label2};
\end{scope}
\path (#1-node1) edge (#1-node2);
\path[draw, shorten >=0pt] ($(#1-node1.north) + (0cm, 0.175cm)$) -| ($(#1-node1) + (2cm,-0.5cm)$) |- ($(#1-node2.south) - (0cm, 0.125cm)$);
}
\newcommand{\insertpicture}{
\begin{tikzpicture}[node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
\tikzstyle{normalnode}=[draw, rectangle, text centered, on chain,
minimum height=0.3cm, text width=3cm]
\tikzstyle{empty}=[text centered, on chain]
\pgfmathtruncatemacro{\boundary}{\n - 1}
\node[empty] (input) {\scriptsize x};
\node[normalnode] (init-node) {\scriptsize label1};
\foreach \twopow in {32, 16, 8} {
\bridgedblock{\twopow-1};
\foreach \name [evaluate=\name as \pred using int(\name - 1)] in {2,...,\boundary} {
\bridgedblock{\twopow-\name};
\path (\twopow-\pred-node2) edge (\twopow-\name-node1);
}
\bridgedblock{\twopow-last}
\path (\twopow-\boundary-node2) edge (\twopow-last-node1);
}
\node[empty] (noboxnode) {\scriptsize noboxnode};
\node[normalnode] (lastnode) {\scriptsize lastnode};
\node[empty] (output) {\scriptsize};
\path (input) edge (init-node);
\path (init-node) edge (32-1-node1);
\path (32-last-node2) edge (16-1-node1);
\path (16-last-node2) edge (8-1-node1);
\path (8-last-node2) edge (noboxnode);
\path (noboxnode) edge (lastnode);
\path (lastnode) edge (output);
\end{tikzpicture}
}
\begin{document}
\chapter{Chapter 1}
\lipsum[1]
\section{Section 1}
\begin{wrapfigure}{O}{0.4\textwidth}
\centering
\insertpicture
\caption{A very very long data flow graph.}
\end{wrapfigure}
\lipsum
\section{Section 2}
\section{Section 3}
\section{Section 4}
\end{document}
我已经尝试过的:
- 使用包
floatflt
会floatingfigure
产生相同的行为。 - 使用
multicol
环境multicols
根本不显示图形。此外,这非常不舒服,因为您需要决定哪些文本放在图形旁边。
也许你们中的一些人知道另一个技巧。
答案1
Wrapfig 希望从段落的开头开始,因此最好在页面顶部获取段落的开头,以便获得完整的页面高度:
\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
decorations.pathreplacing,decorations.pathmorphing,shapes,
matrix,shapes.symbols}
\usepackage{wrapfig}
\def\n{3}
\newcommand{\bridgedblock}[1]{
% args 1: num featuremaps, 2: divide by two, 3: fill color, 4: name prefix
\node[normalnode] (#1-node1) {\scriptsize label1};
\begin{scope}[node distance=0.25cm]
\node[normalnode] (#1-node2) {\scriptsize label2};
\end{scope}
\path (#1-node1) edge (#1-node2);
\path[draw, shorten >=0pt] ($(#1-node1.north) + (0cm, 0.175cm)$) -| ($(#1-node1) + (2cm,-0.5cm)$) |- ($(#1-node2.south) - (0cm, 0.125cm)$);
}
\newcommand{\insertpicture}{
\begin{tikzpicture}[node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
\tikzstyle{normalnode}=[draw, rectangle, text centered, on chain,
minimum height=0.3cm, text width=3cm]
\tikzstyle{empty}=[text centered, on chain]
\pgfmathtruncatemacro{\boundary}{\n - 1}
\node[empty] (input) {\scriptsize x};
\node[normalnode] (init-node) {\scriptsize label1};
\foreach \twopow in {32, 16, 8} {
\bridgedblock{\twopow-1};
\foreach \name [evaluate=\name as \pred using int(\name - 1)] in {2,...,\boundary} {
\bridgedblock{\twopow-\name};
\path (\twopow-\pred-node2) edge (\twopow-\name-node1);
}
\bridgedblock{\twopow-last}
\path (\twopow-\boundary-node2) edge (\twopow-last-node1);
}
\node[empty] (noboxnode) {\scriptsize noboxnode};
\node[normalnode] (lastnode) {\scriptsize lastnode};
\node[empty] (output) {\scriptsize};
\path (input) edge (init-node);
\path (init-node) edge (32-1-node1);
\path (32-last-node2) edge (16-1-node1);
\path (16-last-node2) edge (8-1-node1);
\path (8-last-node2) edge (noboxnode);
\path (noboxnode) edge (lastnode);
\path (lastnode) edge (output);
\end{tikzpicture}
}
\begin{document}
\chapter{Chapter 1}
\lipsum[1]
\section{Section 1}
\enlargethispage{2\baselineskip}
\lipsum[1-3]
\begin{wrapfigure}[44]{o}{0.4\textwidth}
\centering
\insertpicture
\caption{A very very long data flow graph.}
\end{wrapfigure}
\lipsum[4-20]
\section{Section 2}
\section{Section 3}
\section{Section 4}
\end{document}
答案2
我建议将图表放在页边距中。实际上,章节第一页上没有足够的高度来插入图表,\InsertBoxR
而不会影响后续页面的行长,除非您将图表缩小一小倍。这似乎是由于插入了章节标题。
因此我提出以下代码:
\input{insbox.tex}
\documentclass{scrbook}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,trees,positioning,arrows,chains,shapes.geometric,
decorations.pathreplacing,decorations.pathmorphing,shapes,
matrix,shapes.symbols}
\usepackage{wrapfig}
\def\n{3}
\newcommand{\bridgedblock}[1]{
% args 1: num featuremaps, 2: divide by two, 3: fill color, 4: name prefix
\node[normalnode] (#1-node1) {\scriptsize label1};
\begin{scope}[node distance=0.25cm]
\node[normalnode] (#1-node2) {\scriptsize label2};
\end{scope}
\path (#1-node1) edge (#1-node2);
\path[draw, shorten >=0pt] ($(#1-node1.north) + (0cm, 0.175cm)$) -| ($(#1-node1) + (2cm,-0.5cm)$) |- ($(#1-node2.south) - (0cm, 0.125cm)$);
}
\newcommand{\insertpicture}{
\begin{tikzpicture}[node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
\tikzstyle{normalnode}=[draw, rectangle, text centered, on chain,
minimum height=0.3cm, text width=3cm]
\tikzstyle{empty}=[text centered, on chain]
\pgfmathtruncatemacro{\boundary}{\n - 1}
\node[empty] (input) {\scriptsize x};
\node[normalnode] (init-node) {\scriptsize label1};
\foreach \twopow in {32, 16, 8} {
\bridgedblock{\twopow-1};
\foreach \name [evaluate=\name as \pred using int(\name - 1)] in {2,...,\boundary} {
\bridgedblock{\twopow-\name};
\path (\twopow-\pred-node2) edge (\twopow-\name-node1);
}
\bridgedblock{\twopow-last}
\path (\twopow-\boundary-node2) edge (\twopow-last-node1);
}
\node[empty] (noboxnode) {\scriptsize noboxnode};
\node[normalnode] (lastnode) {\scriptsize lastnode};
\node[empty] (output) {\scriptsize};
\path (input) edge (init-node);
\path (init-node) edge (32-1-node1);
\path (32-last-node2) edge (16-1-node1);
\path (16-last-node2) edge (8-1-node1);
\path (8-last-node2) edge (noboxnode);
\path (noboxnode) edge (lastnode);
\path (lastnode) edge (output);
\end{tikzpicture}
}
\usepackage{caption, marginnote, adjustbox}
\begin{document}
\chapter{Chapter 1}
\marginnote{%
\parbox[t]{\marginparwidth}{\centering\adjustbox{width=\marginparwidth}{\insertpicture}
\captionsetup{format=plain, font =footnotesize}\captionof{figure}{A very very long data flow graph.}%
}}%
\lipsum[1]
{\section{Section 1}}%
\lipsum
\section{Section 2}
\section{Section 3}
\section{Section 4}
\end{document}
答案3
我认为问题在于图形(以及用于标题等的所有空间) 做适合原始页面,但不适合文本高度分配的空间。我通过在\vspace*{-4cm}
之前添加centering
以下内容进行了检查wrapfigure
:
\begin{wrapfigure}{O}{0.4\textwidth}
\vspace*{-4cm}
\centering
\insertpicture
\caption{A very very long data flow graph.}
\end{wrapfigure}
...结果页面如下:
乍一看,图表似乎不适合(考虑到它应该适合以下章节标题...)。因此,我将图形定义(在开始时)更改为:
\newcommand{\insertpicture}[1][1.0]{
\begin{tikzpicture}[scale=#1,transform shape, node distance=0.55cm, start chain=going below, shorten >=1pt, ->]
...
现在我已经有了:
\begin{wrapfigure}{O}{0.4\textwidth}
\centering
\insertpicture[0.8]
\caption{A very very long data flow graph.}
\end{wrapfigure}
结果如下:
我想这或多或少就是你所寻找的。