29

I am writing a document with some odd spacing. I am copying another document, and therefore the layout must be almost exact. I have sections divided by letters below, and some paragraphs in each section. Most of these paragraphs should be indented so that they align with the text after each section and not the section number. Will try to clarify with a small code.

I do not have the ability to provide a minimal example, will do so later though

a)   Some section title inserted here with some custom gibberish

How the rest of the paragraph looks with no ident, also a problem 
with several lines as well.

Here is another small part that is not supposed to be indented.  

Here is how I want it to look.

a)   Some section title inserted here with some custom gibberish

     How the rest of the paragraph looks with no ident, also a problem 
     with several lines as well

Here is another small part that is not supposed to be indented  

So yeah, I think I can do it with \hspace*{5mm}. But this only works for single lines. Any suggestions?


Edit: MWE

\documentclass[10pt,a4paper]{article}
\usepackage[hmargin=3cm,vmargin=3.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}

\usepackage{enumitem}
\usepackage{titletoc}
\usepackage{booktabs}
\usepackage{relsize}
\usepackage{array}
\usepackage[hidelinks]{hyperref}
\usepackage[dvipsnames*,svgnames]{xcolor}
\usepackage{mathtools}

\usepackage{fixltx2e}
\usepackage{lmodern}

\newcommand{\oppgave}[2]{\section*{Oppgave #1 {\normalfont\normalsize (#2 poeng)}
\addcontentsline{toc}{section}{Oppgave #1}}}

\newcommand{\del}[1]{\paragraph*{#1)
\addcontentsline{toc}{subsection}{#1)}}}

\newlist{deloppg}{enumerate}{1}
\setlist[deloppg]{label=\arabic*),leftmargin=1.40cm,itemsep=5pt}

\begin{document}

\tableofcontents

\newpage

\section*{Fasitsvar til regneoppgaver}
\addcontentsline{toc}{section}{Fasitsvar til regneoppgaver}

\newpage

\noindent
\phantomsection
\addcontentsline{toc}{section}{{\color{red}\Large{Del 1}}}
\fcolorbox{black}{LightSteelBlue}{\parbox[t][1.25cm][c]{\textwidth}{\begin{center}\textbf{Del 1 \\Uten hjelpemiddler}\end{center}}}

\oppgave{1}{18}

\del{a} \label{1a}
 Vis at den deriverte til funksjonen $O(x) = \dfrac{500}{x} + 8x^2 $ er
 %
 \begin{align*}
 O'(x) = \frac{ \, -500 + 16x^3 \, }{x^2}
 \end{align*}
%
\del{b} Deriver funksjonene \\
\begin{deloppg}
\item  $ f(x) = 3  \ln(2x)       $ 
\item  $ g(x) = 3x \cdot e^{x^2} $ \aa 
\end{deloppg}
%
\vspace{5mm}
%
\del{c} Vi har gitt polynomfunksjonen $f(x)=x^3 - 3x^2 - 13x + 15$
\begin{deloppg}
\item Vis at $f(1)=0$. Bruk polynomdivisjon til å faktorisere $f(x)$  i førstegradsfaktorer
\item Løs ulikheten $f(x)\leq 0$
\end{deloppg} 
%
\vspace{5mm}
%
\del{d}
Mengden av lava som spruter ut per time ved et vulkanutbrudd kan 
tilnærmet beskrives ved et funksjonsuttrykk $f(x)$. Funksjonsverdiene 
er målt i tonn, og $t$ er antall timer etter begynnelsen av utbruddet. \\    \\    Du får vite at: $f(0)=300, \qquad f'(10)=0 \qquad \textnormal{og} \qquad         f''(10) = -10$\\    \\     Hva kan du si om vulkanutbruddet på grunnlag av disse opplysningene? 

\end{document}

I felt I had to include this much of my document to show of where the mistake happens. Was a lot of work finding the packages and such. My preamble only includes 4 packs each with a common theme. So I had to extract all the packages needed to make this page work. The problem is in the last section. Where I want the text to be aligned with the rest. Will try Werner's suggestion =)

David Carlisle
  • 757,742
N3buchadnezzar
  • 11,348
  • 7
  • 55
  • 114

3 Answers3

32

I would use the adjustwidth environment from the changepage package:

\begin{adjustwidth}{<left margin>}{<right margin>}
...
\end{adjustwidth}

The entire contents of adjustwidth are indented from the left margin by <left margin> and from the right margin by <right margin>. Here's a minimal working example:

\documentclass{article}
\usepackage{changepage}% http://ctan.org/pkg/changepage
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\section{Some section title inserted here with some custom gibberish}
\begin{adjustwidth}{2.5em}{0pt}
\lipsum[1]
\end{adjustwidth}
\lipsum[2-5]
\end{document}

Adjustwidth of first paragraph

The standard article document class indents the section title by 2.5em.


Edit: After seeing your minimal working example (MWE), I would suggest using the enumitem package to provide the appropriate margin alignment in your "problem" set. Below is a revised version of your MWE with the correct redefinition.

\documentclass[10pt,a4paper]{article}
\usepackage[hmargin=3cm,vmargin=3.5cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[norsk]{babel}
\usepackage{amsmath}

\usepackage{enumitem}
\usepackage[hidelinks]{hyperref}
\usepackage[dvipsnames*,svgnames]{xcolor}

\newcommand{\oppgave}[2]{\section*{Oppgave #1 {\normalfont\normalsize (#2 poeng)}
\addcontentsline{toc}{section}{Oppgave #1}}}

\newcommand{\del}[1]{%
  \item \addcontentsline{toc}{subsection}{#1)}
}

\newlist{deloppg}{enumerate}{2}
\setlist[deloppg]{label=\arabic*),leftmargin=*,itemsep=5pt}

\begin{document}

\tableofcontents

\newpage

\section*{Fasitsvar til regneoppgaver}
\addcontentsline{toc}{section}{Fasitsvar til regneoppgaver}

\newpage

\noindent
\phantomsection
\addcontentsline{toc}{section}{{\color{red}\Large{Del 1}}}
\fcolorbox{black}{LightSteelBlue}{%
  \parbox[t][1.25cm][c]{\textwidth}{%
    \begin{center}
      \textbf{Del 1 \\Uten hjelpemiddler}
    \end{center}%
  }%
}

\oppgave{1}{18}

\begin{enumerate}[leftmargin=*,labelsep=2em,label=\alph*)]
\del{a} \label{1a}
  Vis at den deriverte til funksjonen $O(x) = \dfrac{500}{x} + 8x^2 $ er
  %
  \begin{align*}
    O'(x) = \frac{ -500 + 16x^3 }{x^2}
  \end{align*}
  %
\del{b} Deriver funksjonene \\ 
\begin{deloppg}
  \item  $ f(x) = 3  \ln(2x)       $ 
  \item  $ g(x) = 3x \cdot e^{x^2} $ \aa 
\end{deloppg}
%
\vspace{5mm}
%
\del{c} Vi har gitt polynomfunksjonen $f(x)=x^3 - 3x^2 - 13x + 15$
\begin{deloppg}
  \item Vis at $f(1)=0$. Bruk polynomdivisjon til å faktorisere $f(x)$  i førstegradsfaktorer
  \item Løs ulikheten $f(x)\leq 0$
\end{deloppg} 
%
\vspace{5mm}
%
\del{d}
  Mengden av lava som spruter ut per time ved et vulkanutbrudd kan 
  tilnærmet beskrives ved et funksjonsuttrykk $f(x)$. Funksjonsverdiene 
  er målt i tonn, og $t$ er antall timer etter begynnelsen av utbruddet. \\ \\ Du får vite at: $f(0)=300, \qquad f'(10)=0 \qquad \textnormal{og} \qquad         f''(10) = -10$\\ \\ Hva kan du si om vulkanutbruddet på grunnlag av disse opplysningene? 
\end{enumerate}
\end{document}

Enumitem defintion for problems

Looking at your code there could be some improvements made. However, since the MWE might only cover a portion of what you're after, I merely tried to make things work the way you want them to.

inavda
  • 136
  • 1
  • 7
Werner
  • 603,163
  • Thanks this almost works. Problem is that if you look at my code. I basically have to do it like this

    \del{a} \begin{adjustwidth}{2.5em}{0pt} \lipsum[1] \end{adjustwidth}

    And the adjustwidth starts a new line. Which is not desirable. Any way to stop the enviroment from starting a new line?

    – N3buchadnezzar Oct 09 '11 at 00:11
  • @N3buchadnezzar: I've added an edit to my answer. From looking at your MWE, it seems like an enumitem approach here would be better, rather than using the adjustwidth environment from changepage. I've updated your code with some suggestions and hope this meets your "indentation needs." – Werner Oct 09 '11 at 01:20
  • @Werner: Just out of curiosity, what language is it you use for edit 1? Could it be Nederlands or Norsk perhaps? – Tom Bombadil Oct 09 '11 at 01:59
  • @TomBombadil: That is from the OP's original MWE. Using Google Translate, it detects Norwegian. "Nederlands" (or Dutch, rather), looks very much like a mixture of Afrikaans and German (perhaps more like the former) to someone who doesn't know it. – Werner Oct 09 '11 at 02:10
  • Thanks Werner , I think that will do it =) What sort of improvements were you talkinb about? I would be very interested in hearing about them. This is the first page of an norwegian exam, for students in the age 17-18. Also the language is norwegian, much closer to german, and dutch than Afrikaans. I can sort of read, netherlandic, some german, sweedish and danish. Since they are so similar – N3buchadnezzar Oct 09 '11 at 10:04
  • Gargle I`ve been sitting here for almost an hour now trying to make it work... Your MWE works perfectly. But it will not work in my document... I get some undefined item problem with \del{b}. Removing all of my packages and just including your example along witht hte rest of my document. Gives me a problem with my next part on the next page. Seems like I have to enumerate my entire document :/ Sigh... So tired trying to make this work.Only most of my document is supposed to be inlined, not everything. I have about 10 pages so... – N3buchadnezzar Oct 09 '11 at 11:00
  • @N3buchadnezzar: It is hard to tell what the problem is without seeing the code. Perhaps post it on GitHub - not sure whether this is possible due to it being an exam. Perhaps you can insert dummy question content but keep the format/scope? Possible improvements stemmed from the fact that you originally used \paragraph to denote an item in a list. Although it worked typographically (until your alignment problem), it was much easier to resort to using enumitem's list formatting capabilities. – Werner Oct 09 '11 at 15:13
  • Thanks for this post. I was able to make a new command, which indented a description on my CV. \newcommand{\explanation}[1]{\begin{adjustwidth}{40pt}{0pt}#1\end{adjustwidth}} – Jonathan Komar Jun 28 '12 at 13:17
  • This added numbers to my subsections for some reason... – byxor Dec 24 '18 at 15:22
4

You could use the ìtemize environment in an unusual way:

\documentclass[parskip]{scrartcl}
\usepackage[margin=50mm]{geometry}

\begin{document}

\begin{itemize}
    \item[a)] Some section title inserted here with some custom gibberish

How the rest of the paragraph looks with no ident, also a problem 
with seveleral lines aswell
\end{itemize}
Here is another smal part that is not supposed to be inlined. Here is another smal part that is not supposed to be inlined. Here is another smal part that is not supposed to be inlined. 
\begin{itemize}
    \item[b)] Some section title inserted here with some custom gibberish

How the rest of the paragraph looks with no ident, also a problem 
with seveleral lines aswell
\end{itemize}

\end{document}

enter image description here

Tom Bombadil
  • 40,123
2
  • You can put the paragraph into a {minipage} and use calc for calcualting

    \usepackage{calc}
    ...
    a)   Text
    
    \hspace*{\fill}\begin{minipage}{\textwidth-5mm}
        Content
    \end{minipage}
    

    If you prefer you could use a \parbox instead

  • use a tabular with two cols

  • use a list environment

  • if using KOMA-Script you can use the addmargin-environment

maybe there are serval more ways but it would be good to have an example …

Tobi
  • 56,353