Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What I want to achieve

Align the first line of a multi-line section head on the grid and consecutive lines according to the baseline distance given in the font definition. The baseline distance of the font used for the section heads does not match the grid distance.

What I have so far

If a section head consists of only one line, then grid=high does what I expect; the first (in fact, the only line) is aligned on the grid. However, when the head consists of more than one line, the last line is always aligned on the grid, instead of the first.

Available documentation

The Details manual lists several values for grid and quite some documentation. But all examples are single-line heads, unfortunately.

The code

\setuplayout [grid=yes]
\definefont  [BigFont]  [Bold at 20pt] [24pt]
\setuphead   [section]  [style=\BigFont, grid=high, before={\blank[4*line]}]

\showgrid
\starttext

  \startsection [title=Lorem ipsum dolor]
    \input ward
  \stopsection

  \startsection [title=Lorem ipsum dolor sit amet consectetur adipisicing elit]
    \input ward
  \stopsection

  % Demonstration what I'd like to achieve
  \blank [4*line]
  \startlinecorrection
    \BigFont\raisebox5pt\vbox\bgroup
      3 Lorem ipsum dolor sit amet consectetur\crlf
      \null\kern20pt adipisicing elit\egroup
  \stoplinecorrection
  \input ward

\stoptext

screenshot

The first single-line head is fine. The second is the wrong multi-line head that wants to be corrected; and the third one is a hack to show how it should look like.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

My approach makes two changes to your code:

  1. Do not place the headings on grid explicitly: remove the option grid=high. (Recommendation based on prior experience.)
  2. Stuff headings into a frame with the parameter location=top.

The code below remains remarkably robust. Even when dealing with headings that take three lines and more, things will remain on grid. There is, however, one property of your example that it does not account for: if the heading is the first element on a new page, the title will skip the first line. Personally, I prefer that to the heading extending upwards into the header.

% macros=mkvi
\setuplayout [grid=yes]
\definefont  [BigFont]  [Bold at 20pt] [24pt]

\unprotect

\newdimen\section_frame_width
\def\section_command#number#title{%
  \section_frame_width\hsize%% we need to calculate the remaining
  \setbox\scratchbox\hbox{#number\space}%% horizontal space
  \advance\section_frame_width by -\wd\scratchbox
  #number\space
  \framed[
    width=\section_frame_width,%% “local” or “fit” doesn’t work
    before=,
    location=top,
    frame=on,%% comment this for production
    align=right,]{#title}%
}

\setuphead   [section]  [
  style=\BigFont,
  after=,
  % grid=high,
  before={\blank[2*line]},
  command=\section_command,
]
\protect

\showgrid

\starttext

  \startsection [title=Lorem ipsum dolor]
    \input ward
  \stopsection

  \dorecurse{4}{%
    \startsection [title=Lorem ipsum dolor sit amet consectetur adipisicing elit]
      \input ward \stopsection %% two lines
    \startsection [title=Lorem ipsum dolor sit amet consectetur adipisicing elit
                         Lorem ipsum dolor sit amet consectetur adipisicing elit]
      \input ward \stopsection %% three
    \startsection [title=Lorem ipsum dolor sit amet consectetur adipisicing elit
                         Lorem ipsum dolor sit amet consectetur adipisicing elit
                         Lorem ipsum dolor sit amet consectetur adipisicing elit]
      \input ward \stopsection %% five
  }

\stoptext

first line of structure title on grid

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.