3

I am trying to use an indented parbox, but the \textwidth command in the width parameter doesn't account for the indentation, and so the text overflows outside of my margin. How could I fix this?

Example:

\documentclass{article}

\usepackage{blindtext}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\begin{document}

\blindtext

\makebox[2cm][l]{Hello}
\parbox[t]{\textwidth}{\blindtext}

\end{document}

enter image description here

3

Use

 \parbox[t]{\dimexpr\textwidth-2cm\relax}{\blindtext}

to reduce the size of the \parbox.

Notes:

  • I also added a trailing % to eliminate the space that gets added after the \makebox.
  • The showframe package was used to show the margins. It is not needed in your actual use case.

enter image description here

Code:

\documentclass{article}

\usepackage{blindtext}
\usepackage{showframe}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\begin{document}

\blindtext

\makebox[2cm][l]{Hello}% <--- Trailing % added
\parbox[t]{\dimexpr\textwidth-2cm\relax}{\blindtext}

\end{document}
  • Perfect - nice and easy solution, thank you :) – Garf Oct 3 '18 at 19:48
0

Rather than a \parbox I suggest a \leftskip based environment:

\documentclass{article}

\usepackage{blindtext,showframe}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\newenvironment{shiftright}[1]
 {%
  \par
  \setlength{\leftskip}{2cm}
  \makebox[0pt][r]{\makebox[2cm][l]{#1}}\ignorespaces
 }
 {\par}

\begin{document}

\blindtext

\begin{shiftright}{Hello}
\blindtext
\end{shiftright}

\end{document}

Alternatively, a list based environment:

\documentclass{article}

\usepackage{blindtext,showframe}

\setlength{\parindent}{0em}
\setlength{\parskip}{1em}

\newenvironment{shiftright}[1]
 {%
  \begin{list}{}{%
    \setlength{\leftmargin}{2cm}%
    \setlength{\topsep}{0pt}%
    \setlength{\partopsep}{0pt}%
  }%
  \item\makebox[0pt][r]{\makebox[2cm][l]{#1}}\ignorespaces
 }
 {\end{list}}

\begin{document}

\blindtext

\begin{shiftright}{Hello}
\blindtext
\end{shiftright}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.