How can I make a specific paragraph have a specific line width?
Asked
Active
Viewed 3.5k times
20
-
1You need the paragraph to be able to span across pages? – Display Name Jun 22 '11 at 09:41
-
In this particular case no span is ok. – Gadi A Jun 22 '11 at 10:40
4 Answers
18
Use \parbox{<linewidth>}{<content>} for the paragraph. Alternatively you can use the very similar minipage environment which also takes the line width as first argument. However, both do not allow page breaks in the paragraph. Also have a look on the quote and quotation environments which narrow the paragraph width.
Martin Scharrer
- 262,582
-
-
-
@xport: I just figured that
\par\begingroup\hsize=<width> ... \par\endgroupmight be also do it and support page breaks. I'm not 100% sure if it is OK this way or if it needs extra care. Anyway,\textwidth,\columnwidthand\linewidthshould all be set to\hsizeas well, I think. – Martin Scharrer Jul 08 '11 at 16:49 -
I tried this but it had strange side effects. A) The lineskip was reduced. B) In addition to the paragraph inside
{<content<}the next paragraph was also affected. Only the second paragraph after the closing}was back to normal. – Jyrki Lahtonen Feb 21 '21 at 16:54
8
The method with \leftskip and \rightskip doesn't work if the reduced width part of the document contains lists. In this case it's best to define an environment based on list:
\usepackage{keyval}
\makeatletter
\define@key{setpar}{left}[0pt]{\leftmargin=#1}
\define@key{setpar}{right}[0pt]{\rightmargin=#1}
\define@key{setpar}{both}{\leftmargin=#1\relax\rightmargin=#1}
\makeatother
\newenvironment{narrow}[1][]
{\list{}{\setkeys{setpar}{left,right}%
\setkeys{setpar}{#1}%
\listparindent=\parindent
\topsep=0pt
\partopsep=0pt
\parsep=\parskip}\item\relax\hspace*{\listparindent}\ignorespaces}
{\endlist}
One can specify the settings in the following ways, that should be easily understood:
\begin{narrow}[left=1cm]
\begin{narrow}[right=2cm]
\begin{narrow}[both=1cm]
\begin{narrow}[left=2cm,right=1cm]
and lists inside the environment will work properly.
egreg
- 1,121,712
6
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\blindtext
\leftskip=1cm
\blindtext
\rightskip=1cm
\blindtext
\leftskip=0pt\rightskip=0pt
\blindtext
\end{document}

3
Good feature: The paragraph can span across pages and be enclosed by a fancy frame.

\documentclass{article}
\usepackage{framed,lipsum,xcolor}
\renewenvironment{leftbar}[1][\hsize]{%
\def\FrameCommand{{\color{red}\vrule width 3pt}\hspace{0pt}\fboxsep=\FrameSep\colorbox{yellow}}%
\MakeFramed{\hsize#1\advance\hsize-\width\FrameRestore}}
{\endMakeFramed}
\begin{document}
\lipsum[1]
\begin{leftbar}[0.5\linewidth]
\lipsum[1-3]
\end{leftbar}
\lipsum[3]
\end{document}
Display Name
- 46,933
-
1I much prefer the
mdframedapproach to defining new frame environments:framed's approach is hard to read... – Seamus Jun 22 '11 at 11:34