How do I indent a whole paragraph at the same distance from my left margin, with the simplest command or environment?
[Tex/LaTex] Indenting a whole paragraph
indentationparagraphs
Related Solutions
I wasn't able to use the settings provided by mdframed
. So I just defined a new enviroment. I think for changing it in mdframed
you would need to patch package internals. Anyway this Solution has no problem with additional spaces.
\documentclass{article}
%\usepackage{lipsum}
\usepackage[framemethod=tikz,%
innerleftmargin=\parindent,%
skipabove=0.6\baselineskip,%
skipbelow=0.6\baselineskip,%
innertopmargin=0.4\baselineskip,%
innerbottommargin=0.4\baselineskip]{mdframed}
\newlength{\defparindent}
\setlength{\defparindent}{\parindent}
% The singleframed environment
\newmdenv[linewidth=0.4pt,%
linecolor=black,%
backgroundcolor=white]{singleframed}
\newenvironment*{singleframedindent}{\begin{singleframed}\setlength{\parindent}{\defparindent}\ignorespaces}{\end{singleframed}}
\begin{document}
\begin{singleframedindent}
qwerty\\
qwerty
qwerty
\end{singleframedindent}
\end{document}
Result is:
You wouldn't have any problem with the space in your example if you would do:
\begin{singleframed}
\setlength{\parindent}{\defparindent}%
qwerty
qwerty
\end{singleframed}
The new line after setlength
is the cause for the additional space. By using the comment tag you don't have any problems.
Update: KOMA-script version 3.17 (or newer)
With KOMA-Script version the command \othersectionlevelsformat
is depreciated. You have to use instead \sectionformat
, \subsectionformat
etc. So the code changes to
% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}
\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}
\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\sectionformat{\parbox{\secnumindent}{\thesection\autodot}}
\renewcommand\subsectionformat{\parbox{\secnumindent}{\thesubsection\autodot}}
\renewcommand\subsubsectionformat{\parbox{\secnumindent}{\thesubsubsection\autodot}}
\renewcommand\paragraphformat{\parbox{\secnumindent}{\theparagraph\autodot}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
% to reset headwidth and footwidth
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para
% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where
\begin{align*}
D_{l} & = \text{the lower date} \\
D_{u} & = \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$.
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}
The result is the same as in the picture below.
If this should be compilable with versions 3.15 and 3.16 too insert
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
\providecommand\sectionformat{}\providecommand\subsectionformat{}
\providecommand\subsubsectionformat{}\providecommand\paragraphformat{}
just before redefining \sectionformat
etc.
KOMA-script version 3.15 and 3.16
You can use the new commands \RedeclareSectionCommand
or \RedeclareSectionCommands
and redefine \othersectionlevelsformat
. So it is still possible to refer to a section number by \ref
:
\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}
\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
To reset the original headwidth and footwidth you can use
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
Code:
% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}
\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}
\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
% to reset headwidth and footwidth
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para
% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where
\begin{align*}
D_{l} & = \text{the lower date} \\
D_{u} & = \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$.
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}
KOMA-Script version 3.14 (or older)
Here is another suggestion using the answer by @Steven but redefining \othersectionlevelsformat
instead of \thesection
. So it is still possible to refer to a section number by \ref
:
\newcommand\p{\paragraph{}\hspace*{-1em}}
\newcommand\secnumindent{1.5cm}
\renewcommand\othersectionlevelsformat[3]{\makebox[0pt][r]{\parbox{\secnumindent}{#3\autodot}}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
Code:
% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}
\setcounter{secnumdepth}{4}
\renewcommand\theparagraph{\thesubsection.\arabic{paragraph}}
\newcommand\p{\paragraph{}\hspace*{-1em}}
\newcommand\secnumindent{1.5cm}
\renewcommand\othersectionlevelsformat[3]{\makebox[0pt][r]{\parbox{\secnumindent}{#3\autodot}}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
% to reset headwidth and footwidth
\usepackage[
headwidth=\the\textwidth+\secnumindent:-\secnumindent,
footwidth=head:-\secnumindent,
headsepline,% to show the headwidth
footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\@addtoreset{paragraph}{subsection}
\@addtoreset{paragraph}{section}
\makeatother
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para
% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where
\begin{align*}
D_{l} & = \text{the lower date} \\
D_{u} & = \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$.
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}
Best Answer
Without any additional packages, you could wrap your paragraph in a
minipage
:In the above example, the paragraph depth correction (via
\prevdepth
is from How to keep a constant baselineskip when using minipages (or \parboxes)?).The indent from the left is set to
3cm
, but can be modified. Also, if a paragraph indent is required, use\indent
within the minipage. All of the afore-mentioned modification can be automated. One caveat is that it will not allow breaking across the page boundary.A rather crude way of doing it as well is to modify
\leftskip
: