1

I want to move title of section left by the following code. However, it fails to move the section number. Why and how to deal with it?

\documentclass{article}
\begin{document}
\section{\makebox[0pt][r]{my section}}|main body
\end{document}

EDIT: I want to move title of section into left margin of page. Meanwhile, the first line of paragraph aligns with the title(not below title as usual), as shown on the following picture. Is there such a method? enter image description here

  • Short and sneaky: \documentclass{article} \usepackage{xcolor} \begin{document} \textcolor{white}{ \section{\makebox[0pt][r]{\textcolor{black}{\protect\thesection~my section}}} } |main body \end{document} – marmot Feb 14 at 7:45
  • Thank you @marnot for your trick to handle the section number and shield the original one. – lyl Feb 14 at 10:26
1

Very simple using titlesec:

\documentclass{article}
\usepackage{titlesec}
\begin{document}
\section{Old section}
\titleformat{\section}% Change section style
{\normalfont\Large\bfseries}% font (normal)
{\hspace{-5em}\thesection}% Label - add some negative horizontal space before
{1em}% Space between label and title
{}% Additional code (unused)
\section{New section}
\end{document}

Output: output

  • I add the optional arg [leftmargin] in your code(and remove \hspace{-5em}), but the title seems not in left margin, and only one word per line in the title of section, why and how to do? – lyl Feb 14 at 10:19
  • I believe this puts the entire title in the margin. So you're seeing 'one word per line' because that's all that will fit in the margin. Hence why I didn't use that optional argument. – Pippip19 Feb 14 at 13:00
  • And is there such a way to put the first line of paragraph in the same line with section title? – lyl Feb 14 at 13:12
  • Yes, the runin predefined format (instead of leftmargin) – Pippip19 Feb 14 at 13:20
  • As the length of title is not constant, is there a better way other than \hspace{-5em}' to put all title in left margin, meanwhile, its related paragraph has the same effect of runin` and hang? I mean, all content of title is in left margin, first line of para is on the same line of title – lyl Feb 14 at 13:24
1

You could use the adjustwidth environment from the changepage package to move the section.

\documentclass{article}
\usepackage{changepage}
\begin{document}
    \begin{adjustwidth}{-2cm}{0pt}
    \section{my section}
    \end{adjustwidth}
    | main body
\end{document}

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.