2

I'm with a document that has margin notes in the section titles. I have programmed a command that works if I don't load titlesec package. Here is a minimal example:


\documentclass[a4,twoside]{article}
\usepackage[spanish]{babel}
\usepackage{blindtext}
\usepackage{changepage}
\usepackage{marginnote}
\usepackage{calc}

% \usepackage{titlesec} % No titlesec crap, works

\setlength{\parindent}{0pt} 
\newcommand{\margen}[2][0pt]{%
  \marginnote{%
    \normalfont\footnotesize
    \checkoddpage    
    \ifoddpage {\parbox[t]{\marginparwidth}{\raggedright{\normalfont\footnotesize#2\normalfont}}}
    \else      {\parbox[t]{\marginparwidth}{\raggedleft{\normalfont\footnotesize#2\normalfont}}}
    \fi
  }[#1]
}


\newlength\altura
\setlength{\altura}{\heightof{{\Large C}}}
%\setlength{\altura}{\heightof{{C}}}
%\setlength{\altura}{0pt}

\begin{document}
\section[Uno]{One\marginnote{Test text}}

\blindtext[1]

\section[Dos]{Two \margen{Another secion note}}
\blindtext[1]

\section[Tres]{Three\margen{\blindtext}}%

\blindtext[2]

\section[Four]%
%{Four \margen[-\altura]{Fourth note \\and a little more text}} %  One of the tests modifying the height.
% With the configuration of this file, it does not work.
{Four \margen{Fourth note \\and a little more text}}
\blindtext[1]

\end{document}

%%%%%%%%%%%%%%%%%%%%%%%%

The problem is that when I activate titlesec, an extra vertical space appears, I don't know where it comes from. I've been testing with marginnote's loading parameters, but it means having to insert vertical elements for the correct alignment. Another solution I was considering, is to force a vertical movement, but I can't find a convenient way to know the size of the extra space included in titlesec.

I would be happy to receive any solution, suggestion or hint to solve this.

Best regards.

Edit:

This is the correct alignment form:

Correct way

And this is the wrong way, when titlesec is loaded:

wrong way

3
  • Shouldn't it be \iffoddpage in which case the code does not compile. What exactly is that off page suppose to do? There are way too many } in that macro
    – daleif
    Commented Jun 27 at 11:02
  • @daleif, You' re right, there was a mistake when copying the code. I've added some screenshots showing the correct and the incorrect alignment
    – carlosv
    Commented Jun 27 at 11:52
  • There is no a4 option. It's a4paper.
    – egreg
    Commented Jun 27 at 12:56

1 Answer 1

1

With titlesec you need to raise by the \baselineskip.

\documentclass[a4paper,twoside]{article}
\usepackage[spanish]{babel}
\usepackage{changepage}
\usepackage{marginnote}
\usepackage{calc}

\usepackage{titlesec} % No titlesec crap, works

\usepackage{lipsum}

\newcommand{\margen}[2][0pt]{%
  \marginnote{%
    \normalfont\footnotesize
    \checkoddpage    
    \parbox[t]{\marginparwidth}{%
      \ifoddpage\raggedright\else\raggedleft\fi#2%
    }%
  }[\dimeval{#1-\baselineskip}]
}

\begin{document}

\section[Uno]{\margen{Test text}One}

\lipsum[1]

\section[Dos]{\margen{Another secion note}Two}
\lipsum[1]

\section[Tres]{Three\margen{\lipsum[3][1-2]}}%

\lipsum[2-3]

\section[Four]%
{Four \margen{Fourth note \\and a little more text}}
With the configuration of this file, it does not work.
\lipsum[1]

\end{document}

I simplified the code. Of course, the margin notes go in the outer margin.

enter image description here

enter image description here

You must log in to answer this question.

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