4

I am using

\def\margin_symbol{\rlap{\protect\makebox[-3cm]{X}}}

which I use in sections as \section{\margin_symbol My Header} to place an X 3cm to the left in the margin; however, my problem is that I'm both using it in sections and subsections and therefore the symbols are placed at different horizontally positions.

Can I somehow place the at an absolute position in the margin rather than 3cm to the left as it does now?

  • I think you're after textpos package, most likely? – user31729 Jun 16 '15 at 22:07
  • As I understand, the problem arises in the table of contents, is that so? Unrelated, but avoid \def\margin_symbol{...} and use \newcommand{\marginsymbol}{...}, With the former you are defining the macro \margin with a nonempty parameter text. – egreg Jun 16 '15 at 22:08
  • Yes, the problem is primarily in the table of contents. I will use \newcommand instead of \def. Thank you :-) – Jamgreen Jun 17 '15 at 6:17
2

This implementation with the tabto package will work with certain limitations. Primarily, when \marginsymbol appears in any sectioning macro argument, it must be the last item in the argument. Second, if you are using a table of contents, or a chapter page-heading, you will need to use the optional argument of the sectioning macro to exclude the margin mark.

\documentclass{book}
\usepackage{tabto,lipsum}
\def\marginsymbol{\protect\marginsymbolhelper}
\def\marginsymbolhelper{\tabto*{-1cm}\makebox[0cm]{$\bullet$}\tabto*{\TabPrevPos}}
\begin{document}
\section[My Header]{My Header\marginsymbol}

\subsection{My subsection Header\marginsymbol}

this is an inline \marginsymbol test. \lipsum[1]

\subsection{My subsubsection Header\marginsymbol}
\end{document}

enter image description here


FOLLOW UP:

The OP asks if it can be done for the table of contents, as well. Here is a way, but it does not address the issue of chapter-page headings that I cited above. So, for the article class, where that is not a direct issue, I provide a revised version of \marginsymbol[<length>] with an optional length argument that is only applied in the toc as an added leftward offset, in order to handle the staggered entries of toc subcategories.

\documentclass{article}
\usepackage{tabto}
\newcommand\marginsymbol[1][0pt]{%
  \tabto*{0cm}\makebox[\dimexpr-1cm-#1\relax][r]{$\bullet$}\tabto*{\TabPrevPos}}
\begin{document}

\tableofcontents
\bigskip
\renewcommand\marginsymbol[1][0pt]{%
  \tabto*{0cm}\makebox[-2cm][c]{$\bullet$}\tabto*{\TabPrevPos}}

\section{My Header\marginsymbol}

\subsection{My subsection Header\marginsymbol[23pt]}

\subsubsection{My subsubsection Header\marginsymbol[55pt]}

\section{My New Header\marginsymbol}

\end{document}

enter image description here

  • Thank you. Is it also possible to have the same behaviour in the table of contents? I think the symbols should be placed exactly at same horizontal position as they are at the sections – Jamgreen Jun 17 '15 at 6:17
  • @Jamgreen Please see my FOLLOW UP for one possibility. – Steven B. Segletes Jun 17 '15 at 11:16
  • Why do the symbols have different sizes? Can't I find a package which gives me the possibility to write something like \section{My header \symbol} with \newcommand{\symbol}{\horizontaltextposition{0cm}{symbol}} where 0cm refers to relative position from the left margin, having these symbols being placed every place where \symbol is used - both in toc and sections? – Jamgreen Jun 17 '15 at 14:21
  • @Jamgreen The symbols have different sizes, because the sectioning fonts have different sizes. I thought that was a plus, but I'll see if I can override that. – Steven B. Segletes Jun 17 '15 at 14:24
  • @Jamgreen In the \renewcommand of \marginsymbol, just replace {$\bullet$} with {\normalsize$\bullet$} if you want bullets of consistent size. – Steven B. Segletes Jun 17 '15 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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