背景

背景

背景

对于列中的浮动,维基百科状态:

默认情况下,标题将向下移动到浮动文本下方,它不会像普通文本那样“包裹”浮动文本。

问题

部分标题消失,而不是移至浮动下方。最终,我尝试在不更改内容的情况下生成以下两种布局(在\starttext和之间\stoptext):

布局

另外,重要的是内容不需要更改,因为还有其他布局使用相同的文档结构。如果内容更改可以通用,以使其他布局不受影响,例如通过添加新的命名空间和命令,那么这将可行。这可能类似于:

\definenamespace[Photograph][
  type=module,
  name=Photograph,
  parent=Photograph,
  setup=list,
  version=1.0,
  style=yes,
  command=list,
]

% ...
\starttext
  \setupInsertPhotograph[
    author=Full Name,
    homepage=http://authorname.com/about.html,
    source=http://flickr.com/authorname/sunset.jpg,
  ]
  % Calls "placefigure" and "externalfigure" using the setup parameters.
  \InsertPhotograph
% ...
\stoptext

然后\InsertPhotograph可以使用宏来定制照片的排版方式,而不依赖于布局。

代码

到目前为止,我有以下代码:

\setupalign[hz,tolerant,]

\setuphead[chapter][footer=empty,]
\setuphead[section][page=yes,]

\setuphead[subsection][
  before={\vskip0.5em},
  after={\vskip0.5em},
]

\setuphead[chapter,section,subsection][header=none,number=no,]

\defineitemgroup[Preparation]
\setupitemgroup[Preparation][each][packed][
  before={\empty},
]

\setupexternalfigures[width=\hsize,]

\definecolumnset[BookColumns][n=2]
\definecolumnsetspan[BookColumnSpan][n=2]

\starttext
  \startchapter[title=Chapter One]
  \page
  \startcolumnset[BookColumns]
    \startsection[title=Section One]
      % This could be \InsertPhotograph instead of \placefigure...
      \placefigure[tblr]{}{\externalfigure[fake][]}

      \startsubsection[title=Subsection]
      \input douglas
      \stopsubsection
      \startsubsection[title=Preparation]
      \startPreparation
      \dorecurse{4} { \startitem Pour liquid helium into flask. \stopitem }
      \stopPreparation
      \stopsubsection
    \stopsection
    \startsection[title=Section Two]
      \dorecurse{4} { \input knuth }
    \stopsection
  \stopcolumnset
  \stopchapter
\stoptext

问题

当有图形时,照片如何浮动到章节标题的左侧,而当没有图形时,章节标题如何跨越页面?

答案1

这里我提出了一个使用分段命令的第二个可选参数的解决方案。

可以使用命令检索值 \structureuservariable。首先,定义自定义头部替代项,检查figure键是否存在。如果存在,则包括图形和节头,否则仅包括节头。然后设置节头以使用自定义头部替代项。

\setupexternalfigures
  [location=default]

\defineframed
  [headframe]
  [width=\textwidth,
   frame=off]

\defineheadalternative
  [graphiccolumn]
  [renderingsetup=graphiccolumn]

\startsetups [graphiccolumn]
  \headsetupspacing
  \doifsomethingelse
    {\structureuservariable{figure}}
    {\headframe
      {\externalfigure[\structureuservariable{figure}]\hfill
       \headnumbercontent\space\headtextcontent}}
    {\headnumbercontent\space\headtextcontent}
\stopsetups

\setuphead
  [section]
  [alternative=graphiccolumn]

\starttext
  \startsection [title=Alpha] [figure=cow]
    \input ward
  \stopsection

  \startsection [title=Beta]
    \input ward
  \stopsection

  \startsection [title=Gamma] [figure=hacker]
    \input ward
  \stopsection
\stoptext

结果

答案2

创建自定义部分以指示何时出现照片 ( sectionpicture) 允许将该部分包装为双列模式并将其标题设为empty。这保留了文档的结构,从而允许多种布局可能性。

也可能使用:

\def\trueref{true}
\startsection[title=Section One][picture=\trueref]
  \Photograph
  % ...
\stopsection

但是,我无法让这种方法奏效。相反,预览之后的代码几乎产生正确的结果。

预览:

结果

代码:

\setuppapersize[letter][letter]
\setuplayout[width=fit,]
\setupalign[hz,tolerant,]

\setuphead[chapter,section,subsection][header=none,number=no,]

\setuphead[chapter][footer=empty,after=\page,]
\setuphead[section][page=yes,]

\setuphead[subsection][
  before={\vskip0.5em},
  after={\vskip0.5em},
  page=no,
]

\setuphead[subsection][
  beforesection={\startmixedcolumns[n=2,balance=no,]},
  aftersection={\stopmixedcolumns},
  page=no,
]

\definehead[sectionpicture][section][
  placehead=empty,
  before={\startcolumns[n=2,]},
  after={\vskip-1em},
]

\defineitemgroup[Preparation]
\setupitemgroup[Preparation][each][packed][
  before={\empty},
]

\setupexternalfigures[
  width=\hsize,
  location={none,left,high},
]

\definenamespace[Photograph][
  type=module,
  name=Photograph,
  parent=Photograph,
  setup=list,
  version=1.0,
  style=yes,
  command=list,
]

% Define parameters within the Photograph namespace.
\setupPhotograph[
  author=,
  homepage=,
  source=,
  % Pass along the current section title into the Photograph macro.
  sectiontitle={\namedstructurevariable{section}{title}},
  attribution=photo:,
  cite={%
    \Word{\Photographparameter{attribution}} %
    \Photographparameter{author}},
]

\setupcaptions[location=,]
\definefloat[photograph][photographs][figure]

\showframe

% Defines how the photograph is used.
\def\Photograph{%
  \placephotograph[top,left,force]{}{\externalfigure[fake][]}
  \columnbreak
  {\switchtobodyfont[24pt]\Photographparameter{sectiontitle}} \par \\
  \Photographparameter{cite}
  \stopcolumns
}

\starttext
  \startchapter[title=Chapter One]
    \startsectionpicture[title=Section One]
      \Photograph

      \startsubsection[title=Subsection]
      \input douglas
      \stopsubsection

      \startsubsection[title=Preparation]
      \startPreparation
      \dorecurse{3} { \startitem Pour liquid helium into flask. \stopitem }
      \stopPreparation
      \stopsubsection
    \stopsectionpicture

    \startsection[title=Section Two]
      \startsubsection[title=Subsection]
      \input knuth
      \stopsubsection

      \startsubsection[title=Preparation]
      \startPreparation
      \dorecurse{3} { \startitem Pour CO$_2$ into beaker. \stopitem }
      \stopPreparation
      \stopsubsection
    \stopsection
  \stopchapter
\stoptext

相关内容