4

In the example below I've introduced a page number conditional \ifnum\c@page=1\relax\else.... The page number conditional (in this case) checks for page number 1 and does nothing if the condition is fulfilled. The conditional also seems to produce strange vertical white space of height \baselineskip. Replacing \relax with \vskip-\baselineskip gives the intended result, as does placing text, e.g. xyz before the first section heading. Neither of these are really solutions to the problem, since I still don't understand what's going on.

As an aside, changing the conditional to a different page number causes the same issue if no text is before the conditional, e.g. two section headings one after another.

So where is the space coming from?

\documentclass{article}
\usepackage[explicit]{titlesec}%
\makeatletter
\usepackage{changepage}
\usepackage{showframe}
\newenvironment{somenevironment}%
  {\begin{adjustwidth*}{0pt}{100pt}%%%<<<<<
  }%
  {\end{adjustwidth*}%%%<<<<<<
  }%
\titleformat{name=\section}%
{}{}{\z@}%
{%
  \ifnum\c@page=1\relax%
  \else%
    \expandafter\clearpage\fi%
%                            ^^^^^^^^^^^
  \begin{somenevironment}%
    #1
  \end{somenevironment}%%%%<<<<
  }%
[\clearpage]
\makeatother
\begin{document}
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\section{My section}xyz
\end{document}
5
  • 1
    The test with \value{page} or \c@page (which is the same) is not reliable because of the asynchronous mechanism for page breaking. The value of the page counter is updated only when a page is shipped out.
    – egreg
    May 11, 2015 at 19:44
  • 1
    after saying in your text that you have \ifnum\c@page=1\relax, your code shows \ifnum\c@page=1%. this is one place where you really do need either a space or \relax to terminate the digit parsing. (but egreg's comment has the real answer.) May 11, 2015 at 19:45
  • @barbarabeeton Thanks for pointing it out, updated.
    – 1010011010
    May 11, 2015 at 19:46
  • The vertical space is caused by adjustwidth. What's the reason for using it?
    – egreg
    May 11, 2015 at 20:00
  • @egreg I have a twoside document with fancy section headers which should spill into the "margin" space.
    – 1010011010
    May 11, 2015 at 20:03

1 Answer 1

1

The vertical space at the beginning is caused by adjustwidth. There are simpler ways to do what you want:

\documentclass{article}
\usepackage{titlesec}
\usepackage{showframe}

\newcommand{\somecommand}[1]{%
  \makebox[\textwidth][l]{\parbox[t]{\dimexpr\textwidth+100pt}{#1}}%
}

\titleformat{name=\section}
  {}{}{0pt}
  {%
   \ifnum\value{page}=1
   \else
     \clearpage
   \fi
   \somecommand
  }[\clearpage]

\begin{document}

\section{My section}xyz
\section{My section}xyz

\end{document}

enter image description here

2
  • What alternatives are there to parbox? I will be typesetting a lot more page elements than just a section heading, e.g. pictures, itemize environments, quotes, etc. parbox may not be suitable for this.
    – 1010011010
    May 11, 2015 at 20:08
  • @1010011010 Use adjustbox, but not in that context.
    – egreg
    May 11, 2015 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .