3

I'm currently using the following layout for my weekly exercises at my university:

\documentclass[a4paper, 12pt]{article}
\usepackage{titlesec}
\usepackage{lipsum}

% section title format and spacing
\titleformat{\subsection}[hang]{\sffamily\Large}{Exercise \arabic{section}.\arabic{subsection}}{0pt}{}[]
\titleformat{\subsubsection}[runin]{}{(\alph{subsubsection})}{0pt}{}[]
\titlespacing{\subsubsection}{0pt}{0.5em}{0.75em}

% subsubsection indentation
\let\svsubsubsection\subsubsection
\def\subsubsection{\leftskip1em\svsubsubsection}

\begin{document}
    \setcounter{section}{1}
    \subsection{}
    \subsubsection{}
        \lipsum[1-2]
    \subsubsection{}
        \[ some\ equation \]
    \subsection{}
\end{document}

How can I align all lines with the start of the first in a subsection, as shown by the following image: enter image description here

And how can I make \[ \] math environments start in the first line of the subsection?

2 Answers2

3

You can use the aligned environment:

enter image description here

Code:

\documentclass[a4paper, 12pt]{article}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{mathtools}% <-- better to load this (it also loads amsmath)

% section title format and spacing \titleformat{\subsection}[hang]{\sffamily\Large}{Exercise \arabic{section}.\arabic{subsection}}{0pt}{}[] \titleformat{\subsubsection}[runin]{}{(\alph{subsubsection})}{0pt}{}[] \titlespacing{\subsubsection}{0pt}{0.5em}{0.75em}

% subsubsection indentation \let\svsubsubsection\subsubsection \def\subsubsection{\leftskip1em\svsubsubsection}

\begin{document} \setcounter{section}{1} \subsection{} \subsubsection{} \lipsum[1-2] \subsubsection{} $\begin{aligned}[t] F &= ma \ E &= mc^2 \end{aligned}$ \subsection{} \end{document}

Peter Grill
  • 223,288
  • Thanks, this answers my second question. I'm sorry that I've put two questions in one post, but I really didn't want to create a second question for a small problem like this. Anyways, I was told to not use $ for math mode as it's TeX style and not LaTeX. But now I see you using it with a reputation of 162k, so what's the truth about $ and \( \)? – jkhsjdhjs Oct 31 '18 at 20:45
  • 1
    @jkhsjdhjs: The reason for keeping unrelated question separate are so that they may also help others in the future, should they encounter a similar problem. Having may unrelated questions lumped together make it difficult to find. – Peter Grill Nov 01 '18 at 06:59
  • 1
    @jkhsjdhjs: @jkhsjdhjs: As per you question regarding \(...\). Yes, using \(...\) is what is recommended as per Are \( and \) preferable to dollar signs for math mode?, but I got used to using $...$ and old habits are hard to break. On the other hand, using $$...$$ for display math should definitely be avoided as per Why is \[...\] preferable to $$..$$. – Peter Grill Nov 01 '18 at 07:02
2

I think it would be much easier and simpler to use an enumerate environment with adhoc parameters. Here is a possible code:

\documentclass[a4paper, 12pt]{article}
\usepackage{amsmath, nccmath}
\usepackage{enumitem}
\usepackage{titlesec}
\usepackage{lipsum}

% section title format and spacing
\titleformat{\subsection}[hang]{\sffamily\Large}{Exercise \arabic{section}.\arabic{subsection}}{0pt}{}[]
\titleformat{\subsubsection}[runin]{}{(\alph{subsubsection})}{0pt}{}[]
\titlespacing{\subsubsection}{0pt}{0.5em}{0.75em}

% subsubsection indentation
\let\svsubsubsection\subsubsection
\def\subsubsection{\leftskip1em\svsubsubsection}

\begin{document}

    \setcounter{section}{1}
    \subsection{}
    \begin{enumerate}[wide = 0.6em, label=(\alph*), leftmargin=*]
      \item \lipsum[1-2]
    \item\leavevmode\vspace{-\baselineskip}\useshortskip \[ \text{some equation} \]
    \lipsum[11]
    \end{enumerate}
    \subsection{}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Thanks for your answer, but I'd prefer a solution without an additional environment, just \subsubsection, if that's even possible. – jkhsjdhjs Oct 31 '18 at 22:19