2

I am working with Overleaf. Currently, I have this:

\documentclass[12pt,a4paper,openany]{extreport}

\usepackage[utf8]{inputenc}

\usepackage[spanish]{babel}

\usepackage{lipsum} \usepackage[spanish]{babel} \usepackage[]{geometry} \geometry{left=2.5cm, right=2cm, top=3cm, bottom=2cm} \addto\captionsspanish{\renewcommand{\chaptername}{\centering CAPÍTULO}}

\usepackage{titlesec} \addto\captionsspanish{ \titleformat {\chapter}[display]{\huge\bfseries}{\chaptertitlename \hspace{0.5ex} \thechapter}{2pt}{\large \thechapter{.} \hspace{1ex} } \titlespacing*{\chapter}{0pt}{-26pt}{0.01cm} }

\addto\captionsspanish{\titleformat{\section} {\normalfont \bfseries}{\thesection}{1em}{} \titlespacing*{\section}{1cm} {0pt} {0pt}}

 \addto\captionsspanish{\titleformat{\subsection}
 {\normalfont \bfseries}{\thesubsection}{1em}{}\titlespacing* 
  {\subsection} 
   {1.25cm}{0pt}{0pt}}


  \begin{document}
   \chapter{Introducción}
    \lipsum[4]
     \section{Marco teórico}
     \lipsum[4]
   \subsection{tema}
   \lipsum[4]
   \end{document}

enter image description here

All the lengths and font sizes are how I need them to be. However, the text does not align with its respective heading title. I need something like this:

enter image description here

As you can see, the text aligns with its respective heading. I have a larger document, so if possible, I want a solution in few lines that would let me affect the whole document. Also, my document is filled with figures, equations, and tables, so if again possible, I would like a solution that wouldn't interfere much with them.

2 Answers2

1

In LaTeX this kind of indentation is the task of list environments, which change \leftmargin (and that is what adjustwidth uses). I have a solution where I make changes to the \chapter, \section, and \subsection commands to invoke such a list environment after it has done its title. It is a bit tricky because the next one must close that list environment before starting a new one, but I have also solved that. So I can give you a solution that gives you the layout exactly as requested, but in such a way that you don't have to change the text body. All code is in the preamble!

You probably have to do something special for tables and figures if you don't want to indent these, but maybe you can do this with adjustwidth. Or probably the table and figure environments can also be patched to temporarily set the \leftmargin to 0.

I have changed the \section and \subsection title formats, to put the number in a \makebox to align the title with the following text. The \chapter format appeared to be already correct. The size of the \subsection box is a bit larger because otherwise it wouldn't fit. This is also reflected in the 3.3cm adaptation for the \subsection.

\documentclass[12pt,a4paper,openany]{extreport} 
 \usepackage{lipsum}
 \usepackage[spanish]{babel}
 \usepackage[]{geometry}
 \geometry{left=2.5cm, right=2cm, top=3cm, bottom=2cm}
 \addto\captionsspanish{\renewcommand{\chaptername}{\centering CAPÍTULO}}

\usepackage{titlesec} \addto\captionsspanish{ \titleformat {\chapter}[display]{\huge\bfseries}{\chaptertitlename \hspace{0.5ex} \thechapter}{2pt}{\large \thechapter{.} \hspace{1ex} } \titlespacing{\chapter}{0pt}{-26pt}{0.01cm} }

\addto\captionsspanish{% \titleformat{\section} {\normalfont \bfseries}{\makebox[1cm][l]{\thesection}}{0pt}{}% \titlespacing*{\section}{1cm}{0pt}{0pt}% }

\addto\captionsspanish{\titleformat{\subsection} {\normalfont \bfseries}{\makebox[1.3cm][l]{\thesubsection}}{0pt}{}% \titlespacing{\subsection} {2cm}{0pt}{0pt}}

\newcommand{\startsectionlist}[1] {% #1 = space \begin{list}{}{\setlength\leftmargin{#1}}\item[] } \newcommand\stopsectionlist{\end{list}} \newcommand\stoppreviouslist{}

\newcommand\adaptsection[2]{% \expandafter\let\csname orig\string#1\endcsname#1 \renewcommand #1[1]{\stoppreviouslist\let\stoppreviouslist\stopsectionlist \csname orig\string#1\endcsname{##1}\startsectionlist{#2}} } \adaptsection\chapter{1cm} \adaptsection\section{2cm} \adaptsection\subsection{3.3cm} \AtEndDocument{\stoppreviouslist}

\begin{document} \chapter{Introducción} \lipsum[4] \section{Marco teórico} \lipsum[4] \subsection{tema} \lipsum[4] \end{document}

enter image description here

0

I think you can iterate the answer in my comment link and have a whole book as you think.

\documentclass{book} \usepackage{changepage}

\usepackage{lipsum} % just for the example

\newenvironment{subs} {\adjustwidth{3em}{0pt}} {\endadjustwidth}

\begin{document} \chapter{One} \lipsum[1] \begin{subs} \section{A section} \lipsum[1] \subsection{A subsection} \lipsum[2] \begin{subs} \subsubsection{One} \lipsum[3] \subsubsection{Two} \lipsum[4] \end{subs} \section{Another section} \lipsum[3] \end{subs} \chapter{Two} \lipsum[2-3] \begin{subs} \section{A section} \lipsum[1] \subsection{Other} \lipsum[2] \begin{subs} \subsubsection{Other1} \lipsum[3] \subsubsection{Other2} \lipsum[4] \end{subs} \section{Another one} \lipsum[8] \end{subs} \end{document}