LuaLaTeX:在两列文档中对齐基线(网格排版)

LuaLaTeX:在两列文档中对齐基线(网格排版)

我正在排版一本包含很多章节、表格、图表和方程式的科学书籍。这本书分为两栏。我的客户要求我确保两栏文本的基线垂直对齐,无论是浮动、方程式还是章节标题。我搜索了一下,发现它似乎比我预想的要复杂。我发现的问题要么是相当老旧,没有提供解决方案, 或者对于我的目的来说太具体了

我的问题是:是否可以使用 LuaLaTeX 设置两列文档,使得无论列中有什么其他元素,两列的基线都位于同一垂直位置?

该文件是非常很长,所以自动化程度越高(全局)越好。到目前为止,我能想到的唯一办法就是手动设置标题和浮动周围的垂直空间,这显然不可能在源代码有 170 万个字符的情况下实现。

我正在添加一个 MWE,其中包含实际文档中的所有设置和包(即使它们与这个 MWE 大多无关)。

\directlua{pdf.setminorversion(7)}
\documentclass[10pt,openany,oneside,twocolumn,fleqn]{book}
\usepackage[paperheight=280mm,paperwidth=205mm,top=26mm,bottom=26mm,margin=20mm]{geometry} % remove heightrounded from the parameters
\usepackage{lmodern}
\usepackage[greek,english,czech]{babel}
\usepackage{csquotes}
\usepackage[hyphens]{url}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{nameref} % Defines a \nameref command, that makes reference to an object by its name (e.g., the title of a section or chapter)
\usepackage{multirow} % Make an entry that will span multiple rows of a table.
\usepackage{array} % An extended implementation of the array and tabular environments which extends the options for column formats (e.g. padding)
\usepackage{gensymb} % Provides generic commands \degree, \celsius, \perthousand, \micro and \ohm which work both in text and maths mode
\usepackage{amsmath} % so we can use multiline equations with equation* or align* environments (uses multline env.)
\usepackage{fancyhdr} % Allows us to set nice headers
\usepackage{tabularx} % Autofit columns to text width
\usepackage[newcommands]{ragged2e} % hyphenation inside table cells - https://tex.stackexchange.com/questions/16842/auto-fit-table-column-widths-based-on-content/16867
\usepackage{lscape} % landscape certain pages
\usepackage{url} % print URLs nicely
\usepackage{wrapfig} % text flow around images
\usepackage{placeins} % force a float to be in the exact place where we say when it's wrapped surrounded by \FloatBarrier
\usepackage{siunitx} % typeset units properly -- we won't use this because the typesetting is problematic for the sed script to replace: \SI{1.55}{\micro\metre}
\usepackage{caption} % figure/tables tweaking
\usepackage{upgreek} % typeset greek letters straight (not italics) outside of math env (we need to do some hardcore regexing to replace this only outside of math env)
\usepackage{xfrac} % this enables us to use the small diagonal fractions with \sfrac{num}{denum} (in math mode)
\usepackage{dblfloatfix} % redefines latex core to enable images in twocolumn layout "be placed in the right order and introduces position [tbp]"
\usepackage{cuted} % this enables us to use env. strip (for quotes at the chapter beginning)
\usepackage{epigraph} % package for the quotes we have at the beginning of each chapter;; not used right now
\usepackage{microtype} % microtypography to adjust the subtle stuff normal mortals don't see (not even me actually)
\usepackage[dvipsnames]{xcolor} % allows to use colors in the document, dvipsnames allows more names of the colors than the basic package setting
\usepackage{makecell} % create cell boxes inside table cells to be able to wrap text inside them
\usepackage{enumitem} % This package provides user control over the layout of enumerate, itemize and description. (e.g. for changing numbering style)
\usepackage{extarrows} % package allowing variable arrows in the document, e.g. \xrightarrow[{}]{} . Details here: http://www.sascha-frank.com/Arrow/latex-arrows.html
\usepackage{sectsty} % allow coloring the chapter/section headings (colors, alignment, ...)
\usepackage{balance}
\usepackage{changepage} % set different margins for a part of the document (adjustwidth env.)

% This should ensure we won't have large gaps between paragraph where there's no way to fit some other text into the page. But the price will be inconsistent page-content height
\raggedbottom

\definecolor{hbuGreen}{HTML}{005813}
\definecolor{grayRule}{HTML}{acacac}

\chapterfont{\color{hbuGreen}\raggedright}  % sets colour of chapters
\sectionfont{\color{hbuGreen}\raggedright}  % sets colour of sections
\subsectionfont{\color{hbuGreen}\raggedright}  % sets colour of subsections

% setup the capion (figure, table) style
\captionsetup{
    font=footnotesize, % smaller font for all captions
    justification=raggedright, % left align all captions
    labelfont=bf,
    labelsep=period,
    margin=0pt,
    singlelinecheck=false, % disable the automatic latex captions centering
    skip=2mm
}

\sisetup{
    output-decimal-marker = {,},
    group-separator = {\:},
    retain-explicit-plus
} % tell siunitx to use comma as a decimal separator, not dot

% Here is a macro \shifttext{<len>}{<stuff>} that shifts <stuff> by <len> (negative for left, positive for right)
\makeatletter
\newcommand*{\shifttext}[2]{%
  \settowidth{\@tempdima}{#2}%
  \makebox[\@tempdima]{\hspace*{#1}#2}%
}
\makeatother

% Code to change the \paragraph{} definition
\makeatletter
\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
    {3.25ex \@plus1ex \@minus.2ex}%
    % {-1em}%
    {-0.3em}%
    {\normalfont\bfseries}}
\makeatother

\parskip 0pt

\graphicspath{ {lipsum-imgs/} }

\linespread{1.1}
\setlength\emergencystretch{1em}
\setlength{\columnsep}{8mm}

% paragraph and equation indentation
\setlength{\mathindent}{1.3em}
\setlength{\parindent}{1.3em}

\widowpenalty10000
\clubpenalty10000

\renewcommand{\arraystretch}{1.2} % set vertical padding for tables
\setlength{\tabcolsep}{2pt} % set horizontal padding for tables

\newcommand{\subs}[1]{{\textsubscript{#1}}}
\newcommand{\sups}[1]{{\textsuperscript{#1}}}

\newcommand{\itNameRef}[1]{\textit{\nameref{#1}}}

% introduce style for narrower/wider text (use \spacedstyle{+-N} where + is wider, - is narrower)
\newcommand\spacedstyle[1]{\SetTracking{encoding=*}{#1}\lsstyle}

% two new columns for tabularx, equivalents for X with different alignment - Y: center, Z: right
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcolumntype{Z}{>{\raggedleft\arraybackslash}X}

\setlength{\headheight}{28pt}

% \setlist{topsep=3pt,partopsep=3pt,itemsep=1pt}
\setlist{topsep=0pt,partopsep=0pt,itemsep=0pt,parsep=0pt}

\setlength{\epigraphwidth}{\textwidth}
\makeatletter \renewcommand{\@epirule}{\vspace{-1.5em}\begin{flushright}\rule[.5ex]{0.4\textwidth}{\epigraphrule}
                        \vspace{0.5em}\end{flushright}} \makeatother

% using german quotes as they're the same as Czech: https://tex.stackexchange.com/a/268523/92041
\DeclareQuoteAlias{german}{czech}

\begin{document}
    \chapter{Lorem ipsum} % (fold)
    \label{cha:lorem_ipsum}
         Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed iaculis condimentum odio at sollicitudin. Donec semper luctus odio, a elementum ex finibus tempus. Pellentesque sagittis, dolor sit amet mollis molestie, tortor lorem posuere lorem, nec interdum leo risus eget urna. Nunc suscipit orci quis sem aliquet tincidunt. Donec ac eros neque. Vestibulum metus magna, vehicula id accumsan in, porttitor nec velit. Etiam a rhoncus metus. Praesent nec sem tortor. Donec egestas mi at odio dapibus, a feugiat libero efficitur. Vestibulum dictum, dui sit amet imperdiet fermentum, risus erat iaculis velit, vel dapibus sem libero a lorem. Pellentesque sed tellus non nisl volutpat placerat eget ut tortor. Aenean et eros est. Vivamus nec finibus quam, et porta ipsum. Nullam posuere convallis est, at congue erat tempus quis. Curabitur dictum eros in elit varius volutpat.

        Ut egestas facilisis ligula, non ultrices dolor sagittis eget. Nunc euismod, quam et efficitur luctus, urna ex convallis est, at vehicula enim sem at nisi. Vivamus ultrices iaculis ipsum, id tincidunt erat maximus sit amet. Nam sollicitudin neque sed lectus vulputate fermentum. Nam et sem pharetra diam venenatis pellentesque nec in lectus. Integer efficitur nunc in faucibus gravida. Sed hendrerit vulputate nulla eu vestibulum. Suspendisse tincidunt, dui eget mollis tristique, metus ipsum aliquet lectus, sit amet mattis orci elit nec mauris. 

            \begin{figure}[htp]
                \includegraphics[width=\columnwidth]{lipsum-image-480.png}
                \caption{Suspendisse pulvinar risus quis urna scelerisque iaculis. Nulla consequat erat ligula.}
            \end{figure}

        \section{Dolor sit amet} % (fold)
        \label{sec:sit_dolor_amet}
             Duis nec vehicula ipsum, iaculis auctor nisi. Curabitur lacinia id eros et scelerisque. Nunc a sapien ac nisl finibus tincidunt ac aliquam erat. Sed ac varius mi. Proin vitae tincidunt tellus. Suspendisse euismod quam ac ante vestibulum, in eleifend ex molestie. Cras vel libero sapien. Nulla sodales, odio ac egestas ultrices, libero urna luctus sem, et laoreet lorem mi vitae tortor.

            Vivamus consequat sem felis, nec sagittis nisl eleifend ac. Nulla facilisi. Suspendisse pulvinar risus quis urna scelerisque iaculis. Nulla consequat erat ligula. Etiam vitae semper nisl. Curabitur euismod, est hendrerit finibus vestibulum, turpis nisl semper nisi, vel vulputate ligula est vitae ante. Integer ultricies accumsan ante. Aliquam auctor volutpat dictum. Aliquam eget iaculis sapien. Etiam rhoncus dignissim ex quis accumsan. 

            \begin{equation}
                E=m\cdot c^2
                \label{eq:1-01}
            \end{equation}

            \begin{figure*}[htp]
                \centering
                \includegraphics[width=0.7\textwidth]{lipsum-image-282.png}
                \caption{Proin vitae tincidunt tellus. Suspendisse euismod quam ac ante vestibulum, in eleifend ex molestie. Cras vel libero sapien. Nulla sodales, odio ac egestas ultrices, libero urna luctus sem, et laoreet lorem mi vitae tortor.}
            \end{figure*}

             Suspendisse convallis nisl vel viverra gravida. Suspendisse sem mauris, tincidunt at pretium id, venenatis ut ligula. Proin luctus, orci in mollis feugiat, sapien ipsum pharetra sem, at consequat lorem neque at lacus. Nullam euismod enim condimentum odio mattis pulvinar. Quisque nec massa consectetur, iaculis metus laoreet, fermentum erat. Pellentesque sodales porttitor efficitur. Sed sed sollicitudin lacus. Integer tincidunt ipsum id urna imperdiet ornare. Integer leo risus, rhoncus et semper a, imperdiet in magna. Duis sagittis ipsum nec mauris ullamcorper, at porttitor sem molestie. 

             \subsection{Consectetur} % (fold)
             \label{sub:consectetur}

                 Proin tempus, lorem id malesuada auctor, lorem arcu suscipit velit, id consectetur tellus tortor nec eros. Interdum et malesuada fames ac ante ipsum primis in faucibus. Donec non euismod urna. Aenean sit amet pellentesque magna. Aliquam consectetur, dui id lacinia tempor, leo diam laoreet orci, sed fringilla lorem diam ac ex.

                 Praesent ullamcorper mi id orci tempus eleifend. Phasellus quis purus ex. Praesent at elit ligula. Aliquam nec tellus a est accumsan tempus id eget sem. Morbi vehicula posuere urna non viverra. Aenean suscipit vulputate lorem sed mollis. Morbi luctus augue ac odio aliquam, a hendrerit ante finibus. Phasellus mauris ipsum, lacinia non congue mattis, egestas vitae augue. Aenean erat nunc, vestibulum quis lectus a, suscipit vestibulum mi. Donec commodo tristique ante, sed mollis elit porta at. In placerat cursus egestas. 

                \begin{figure}[htp]
                    \centering
                    \includegraphics[width=0.7\columnwidth]{lipsum-image-480.png}
                    \caption{Suspendisse pulvinar risus quis urna scelerisque iaculis. Nulla consequat erat ligula.}
                \end{figure}

                 Integer sit amet velit pharetra, fermentum dui sit amet, posuere magna. Vivamus ut sem elit. In interdum sit amet mauris eu bibendum. Morbi eu felis interdum, egestas ipsum eget, mattis metus. Suspendisse consequat nulla ultrices elit consequat dictum. Quisque interdum eros a nisi viverra scelerisque. Sed fermentum, arcu ut porta aliquet, lorem eros scelerisque dolor, eu blandit quam lectus ut nisi. 

             % subsection consectetur (end)
        % section sit_dolor_amet (end)

        \section{Vestibulum sodales} % (fold)
        \label{sec:vestibulum_sodales}

             Vestibulum sodales eu risus et lacinia. Maecenas feugiat lorem dignissim, pulvinar augue nec, maximus mi. Praesent ut metus nisl. Sed sem nisl, blandit quis malesuada vel, posuere id risus. Sed quis justo vitae eros gravida cursus vel in felis. Ut est lacus, cursus vel ultrices eu, volutpat in ipsum. Vivamus facilisis ipsum at nulla convallis, ut volutpat ante euismod. Fusce nisl nisi, maximus nec faucibus vel, aliquet in turpis. Ut semper, sapien et porttitor tempus, nisi magna sollicitudin eros, finibus sagittis diam elit quis diam. Proin sed metus nec enim pulvinar pretium a at urna. Donec magna erat, lobortis a elementum eget, congue id felis. Morbi nisl turpis, mollis eget dui eu, fringilla convallis lectus. Fusce at mauris bibendum, posuere risus vel, fermentum sem. Cras efficitur malesuada odio vitae suscipit. Pellentesque fringilla, sem eget molestie malesuada, velit purus faucibus lectus, eu fringilla nibh augue ac augue:
             \begin{equation}
                S=v\cdot t\;,
                \label{eq:1-02}
             \end{equation}
              integer condimentum nibh odio, non malesuada ex fermentum et. Fusce et tincidunt enim, nec commodo ex. Nulla facilisi. In purus nibh, ultricies eu nibh in, laoreet tempus tortor. Praesent a lorem viverra, faucibus sem at, finibus risus. Donec ornare purus.

        % section vestibulum_sodales (end)
    % chapter lorem_ipsum (end)
\end{document}

在此处输入图片描述

正如您所看到的,基线在图像、章节标题等之后立即错位。这个问题的目标是让它们始终保持对齐(即改变浮动、标题等周围的间距。我猜)。

  • 我的 LuaLaTeX 版本是:(This is LuaTeX, Version 1.0.4 (TeX Live 2017/Debian)从默认 Ubuntu 存储库安装)
  • 我的操作系统:Ubuntu 18.04 -$ uname -srvpio Linux 4.15.0-76-generic #86-Ubuntu SMP Fri Jan 17 17:24:28 UTC 2020 x86_64 x86_64 GNU/Linux

下面是我在文件中包含的软件包的版本(添加\listfiles到源中以获取此版本):

*File List*
    book.cls    2014/09/29 v1.4h Standard LaTeX document class
   fleqn.clo    2016/12/29 v1.2a Standard LaTeX option (flush left equations)
    bk10.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
geometry.sty    2010/09/12 v5.6 Page Geometry
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
   ifpdf.sty    2017/03/15 v3.2 Provides the ifpdf switch
  ifvtex.sty    2016/05/16 v1.6 Detect VTeX and its facilities (HO)
 ifxetex.sty    2010/09/12 v0.6 Provides ifxetex conditional
 lmodern.sty    2009/10/30 v1.6 Latin Modern Fonts
   babel.sty    2018/02/14 3.18 The Babel package
   greek.ldf    2016/09/07 v1.9g Greek support for the babel system
  lgrenc.def    2015/12/07 v0.13.1 LGR Greek font encoding definitions
greek-fontenc.def    2015/08/04 v0.13 Common Greek font encoding definitions
 english.ldf    2017/06/06 v3.3r English support from the babel system
   czech.ldf    2008/07/06 v3.1a Czech support from the babel system
csquotes.sty    2018/02/11 v5.2c context-sensitive quotations (JAW)
etoolbox.sty    2018/02/11 v2.5e e-TeX tools for LaTeX (JAW)
csquotes.def    2018/02/11 v5.2c csquotes generic definitions (JAW)
csquotes.cfg    
     url.sty    2013/09/16  ver 3.4  Verb mode for urls, etc.
graphicx.sty    2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty    2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg    2016/06/04 v1.11 sample graphics configuration
  luatex.def    2018/01/08 v1.0l Graphics/color driver for luatex
setspace.sty    2011/12/19 v6.7a set line spacing
 nameref.sty    2016/05/21 v2.44 Cross-referencing by name of section
refcount.sty    2016/05/16 v3.5 Data extraction from label references (HO)
 ltxcmds.sty    2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
infwarerr.sty    2016/05/16 v1.4 Providing info/warning/error messages (HO)
gettitlestring.sty    2016/05/16 v1.5 Cleanup title references (HO)
kvoptions.sty    2016/05/16 v3.12 Key value format for package options (HO)
kvsetkeys.sty    2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty    2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty    2016/05/16 v1.4 Provides the ifluatex switch (HO)
multirow.sty    2016/11/25 v2.2 Span multiple rows of a table
   array.sty    2016/10/06 v2.4d Tabular extension package (FMi)
 gensymb.sty    2003/07/02 v1.0 (WaS)
 amsmath.sty    2017/09/02 v2.17a AMS math features
 amstext.sty    2000/06/29 v2.01 AMS text
  amsgen.sty    1999/11/30 v2.0 generic functions
  amsbsy.sty    1999/11/29 v1.2d Bold Symbols
  amsopn.sty    2016/03/08 v2.02 operator names
fancyhdr.sty    2017/06/30 v3.9a Extensive control of page headers and footers
tabularx.sty    2016/02/03 v2.11 `tabularx' package (DPC)
ragged2e.sty    2009/05/21 v2.1 ragged2e Package (MS)
everysel.sty    2011/10/28 v1.2 EverySelectfont Package (MS)
  lscape.sty    2000/10/22 v3.01 Landscape Pages (DPC)
 wrapfig.sty    2003/01/31  v 3.6
placeins.sty    2005/04/18  v 2.2
 siunitx.sty    2017/11/26 v2.7k A comprehensive (SI) units package
   expl3.sty    2018/02/21 L3 programming layer (loader) 
expl3-code.tex    2018/02/21 L3 programming layer 
l3pdfmode.def    2017/03/18 v L3 Experimental driver: PDF mode
  xparse.sty    2018/02/21 L3 Experimental document command parser
l3keys2e.sty    2018/02/21 LaTeX2e option processing using LaTeX3 keys
translator.sty    2018/01/04 v1.12 Easy translation of strings in LaTeX
 caption.sty    2016/02/21 v3.3-144 Customizing captions (AR)
caption3.sty    2016/05/22 v1.7-166 caption3 kernel (AR)
 upgreek.sty    2003/02/12 v2.0 (WaS)
   xfrac.sty    2018/02/21 L3 Experimental split-level fractions
textcomp.sty    2017/04/05 v2.0i Standard LaTeX package
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
xtemplate.sty    2018/02/21 L3 Experimental prototype document functions
dblfloatfix.sty    2012/12/31 v1.0a (JAW)
fixltx2e.sty    2016/12/29 v2.1a fixes to LaTeX (obsolete)
   cuted.sty    2012/10/04 v1.5 Mixing onecolumn and twocolumn modes
epigraph.sty    2009/09/02 v1.5c typesetting epigraphs
microtype.sty    2018/01/14 v2.7a Micro-typographical refinements (RS)
microtype-luatex.def    2018/01/14 v2.7a Definitions specific to luatex (RS)
microtype.cfg    2018/01/14 v2.7a microtype main configuration file (RS)
  xcolor.sty    2016/05/11 v2.12 LaTeX color extensions (UK)
   color.cfg    2016/01/02 v1.6 sample color configuration
dvipsnam.def    2016/06/17 v3.0m Driver-dependent file (DPC,SPQR)
makecell.sty    2009/08/03 V0.1e Managing of Tab Column Heads and Cells
enumitem.sty    2011/09/28 v3.5.2 Customized lists
extarrows.sty    2008/05/15 v1.0b Some extensible arrows
 sectsty.sty    2002/02/25 v2.0.2 Commands to change all sectional heading style
s
 balance.sty    1999/02/23 4.3 (PWD)
changepage.sty    2009/10/20 v1.0c check page and change page layout
  lgrcmr.fd    2017/07/29 v1.2 Greek European Computer Regular
  ts1cmr.fd    2014/09/29 v2.5h Standard LaTeX font definitions
supp-pdf.mkii
epstopdf-base.sty    2016/05/15 v2.6 Base part for package epstopdf
  grfext.sty    2016/05/16 v1.2 Manage graphics extensions (HO)
kvdefinekeys.sty    2016/05/16 v1.4 Define keys (HO)
pdftexcmds.sty    2018/01/21 v0.26 Utility functions of pdfTeX for LuaTeX (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
translator-basic-dictionary-English.dict    
siunitx-abbreviations.cfg    2017/11/26 v2.7k siunitx: Abbreviated units
mt-LatinModernRoman.cfg    2013/03/13 v1.0 microtype config. file: Latin Modern 
Roman (RS)
  ot1lmr.fd    2009/10/30 v1.6 Font defs for Latin Modern
  omllmm.fd    2009/10/30 v1.6 Font defs for Latin Modern
 omslmsy.fd    2009/10/30 v1.6 Font defs for Latin Modern
 omxlmex.fd    2009/10/30 v1.6 Font defs for Latin Modern
  mt-eur.cfg    2006/07/31 v1.1 microtype config. file: AMS Euler Roman (RS)
  ts1lmr.fd    2009/10/30 v1.6 Font defs for Latin Modern
 ot1lmss.fd    2009/10/30 v1.6 Font defs for Latin Modern
 ot1lmtt.fd    2009/10/30 v1.6 Font defs for Latin Modern

我很高兴能得到一些指导,或者至少能得到有关这个问题的信息。即使应该是“这不可能做到”。

相关内容