使用包裹浮动时,我总是会遇到一个问题,那就是它们会从其所属段落的开头开始一行。现在我发现了一个技巧,如何将它们提升到这里但是使用它会对文档中其他位置的全宽浮动产生意想不到的后果。
诀窍是将此行添加到序言中:
\setlength{\intextsep}{0cm plus1cm minus1cm}
它对包裹的浮动很有效,但上面和下面的文本一些其他浮动现在将进入图形 - 似乎没有规则现在浮动上方和下方有多少空间。有些看起来像以前一样,而其他的则将有文本进入其中,无论我在浮动上方和下方添加多大的垂直空间。
我讨厌手动调整每个浮动元素周围的空间,我害怕回到浮动元素对齐不佳的时代。这是怎么回事?我应该怎么做才能让浮动元素对齐正确和是否有足够的、一致的空间供常规浮点使用?
编辑:这是同一个 LyX 文件的结果,左侧没有那一行,右侧有那一行。我还擅自将右侧版本的换行行数减少了一行。显然,右侧换行浮动的垂直位置看起来更好,但右侧浮动的垂直位置变得更糟。
以下是右侧的源代码(带有“特殊”行):
#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\begin_preamble
\setlength{\intextsep}{0cm plus1cm minus1cm}
\end_preamble
\options twopage
\use_default_options false
\begin_modules
fixltx2e
fix-cm
\end_modules
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding auto
\fontencoding default
\font_roman "cmr" "default"
\font_sans "lmss" "default"
\font_typewriter "lmtt" "default"
\font_math "auto" "auto"
\font_default_family sfdefault
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize a4paper
\use_geometry false
\use_package amsmath 1
\use_package amssymb 0
\use_package cancel 0
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip smallskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Chapter
Headline
\end_layout
\begin_layout Standard
\begin_inset Wrap figure
lines 9
placement O
overhang 0in
width "50col%"
status open
\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
filename /Users/Peter/Desktop/pic.PNG
lyxscale 20
width 48text%
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption Standard
\begin_layout Plain Layout
Sample wrapped float
\end_layout
\end_inset
\end_layout
\end_inset
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
\end_layout
\begin_layout Standard
\begin_inset Float figure
placement !h
wide false
sideways false
status open
\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
filename pic.PNG
lyxscale 20
width 70text%
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption Standard
\begin_layout Plain Layout
Sample float
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit
laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end_layout
\end_body
\end_document
以下是我将文件导出为 pdflatex 时的输出:
%% LyX 2.2.2 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\RequirePackage{fix-cm}
\RequirePackage{fixltx2e}
\documentclass[12pt,a4paper,oneside,twopage]{scrbook}
\renewcommand{\rmdefault}{cmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{wrapfig}
\usepackage{graphicx}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
\setlength{\intextsep}{0cm plus1cm minus1cm}
\makeatother
\begin{document}
\chapter{Headline}
\begin{wrapfigure}[9]{O}{0.5\columnwidth}%
\begin{centering}
\includegraphics[width=0.48\textwidth,height=7\baselineskip]{example-image}
\par\end{centering}
\caption{Sample wrapped float}
\end{wrapfigure}%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus
error sit voluptatem accusantium doloremque laudantium, totam rem
aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur
magni dolores eos qui ratione voluptatem sequi nesciunt.
\begin{figure}[!h]
\begin{centering}
\includegraphics[width=0.7\textwidth]{example-image}
\par\end{centering}
\caption{Sample float}
\end{figure}
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut
labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima
veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,
nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure
reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end{document}
答案1
该长度\intextsep
由位于文本页面内的浮点数(根据参数)使用,[h]
而不是浮动到页面的顶部或底部或添加到浮动页面。
0cm plus1cm minus1cm
长度的自然宽度(首选宽度)为 0cm,但如果页面内容需要拉伸,则可以拉伸到 1cm,如果页面过满且空白需要缩小,则可以缩小到 -1cm。
因此,此设置表明,如果将浮动元素设置在页面中间,则它可能会被上下 1cm 的负空间所包围,从而会按该量叠印文本,或者可能会被浮动元素上下最多 1cm 的空白所包围。
基本上,没有文档需要此设置。它不一定会产生糟糕的排版。它可能会意外地延伸到合理的空间,例如 10pt 左右,但那只是运气好而已。
为了进行比较,标准课程(10pt 选项)使用以下设置
\setlength\intextsep {12pt plus 2pt minus 2pt}
因此空间在 10pt 和 14pt 之间,自然大小为 12pt。
wrapfig
将这个空间添加到包装的图形中,因此如果你想全局设置它,那么使用就足够了
\setlength\intextsep {0pt}
不允许 1cm 的过度打印,但最好保留h
浮点数,只需修补 wrapfig 即可删除\intextspace
顶部
%% LyX 2.2.2 created this file. For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\RequirePackage{fix-cm}
\RequirePackage{fixltx2e}
\documentclass[12pt,a4paper,oneside,twopage]{scrbook}
\renewcommand{\rmdefault}{cmr}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\renewcommand{\familydefault}{\sfdefault}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{0pt}
\usepackage{wrapfig}
\usepackage{graphicx}
\makeatletter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.
\pdfpageheight\paperheight
\pdfpagewidth\paperwidth
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands.
%\setlength{\intextsep}{0cm}% plus1cm minus1cm}
\usepackage{etoolbox}
\patchcmd\WF@rapt{\vtop\bgroup}{\vtop\bgroup\vspace{-\intextsep}}{}{}
\makeatother
\begin{document}
\chapter{Headline}
\begin{wrapfigure}[9]{O}{0.5\columnwidth}%
\begin{centering}
\includegraphics[width=0.48\textwidth,height=7\baselineskip]{example-image}
\par\end{centering}
\caption{Sample wrapped float}
\end{wrapfigure}%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum. Sed ut perspiciatis unde omnis iste natus
error sit voluptatem accusantium doloremque laudantium, totam rem
aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto
beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur
magni dolores eos qui ratione voluptatem sequi nesciunt.
\begin{figure}[!h]
\begin{centering}
\includegraphics[width=0.7\textwidth]{example-image}
\par\end{centering}
\caption{Sample float}
\end{figure}
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut
labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima
veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam,
nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure
reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end{document}
答案2
经过多次尝试和错误,最有效的方法是在浮动内的图片顶部添加 -4mm 的负垂直空间。只有当浮动与新页面的第一行一起放置时,才必须省略此负垂直空间。
现在,来自问题的 LyX 示例文本源(没有“特殊”行)如下所示(请注意部分\begin_inset VSpace -4mm \end_inset
- 这会产生很大的不同!):
#LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 508
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass scrbook
\begin_preamble
\end_preamble
\options twopage
\use_default_options false
\begin_modules
fixltx2e
fix-cm
\end_modules
\maintain_unincluded_children false
\language english
\language_package none
\inputencoding auto
\fontencoding default
\font_roman "cmr" "default"
\font_sans "lmss" "default"
\font_typewriter "lmtt" "default"
\font_math "auto" "auto"
\font_default_family sfdefault
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize 12
\spacing single
\use_hyperref false
\papersize a4paper
\use_geometry false
\use_package amsmath 1
\use_package amssymb 0
\use_package cancel 0
\use_package esint 1
\use_package mathdots 0
\use_package mathtools 0
\use_package mhchem 0
\use_package stackrel 0
\use_package stmaryrd 0
\use_package undertilde 0
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip smallskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header
\begin_body
\begin_layout Chapter
Headline
\end_layout
\begin_layout Standard
\begin_inset Wrap figure
lines 11
placement O
overhang 0in
width "50col%"
status open
\begin_layout Plain Layout
\noindent
\align center
\begin_inset VSpace -4mm
\end_inset
\begin_inset Graphics
filename pic.PNG
lyxscale 20
width 50text%
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption Standard
\begin_layout Plain Layout
Sample wrapped float
\end_layout
\end_inset
\end_layout
\end_inset
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi
ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore
eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium
doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore
veritatis et quasi architecto beatae vitae dicta sunt explicabo.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit,
sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
\end_layout
\begin_layout Standard
\begin_inset Float figure
placement !h
wide false
sideways false
status open
\begin_layout Plain Layout
\noindent
\align center
\begin_inset Graphics
filename pic.PNG
lyxscale 20
width 70text%
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption Standard
\begin_layout Plain Layout
Sample float
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur,
adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore
et dolore magnam aliquam quaerat voluptatem.
Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit
laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum
iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae
consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
\end_layout
\end_body
\end_document