1

I'm using displayquote and texttt to write a piece of software code in a LaTeX document:

\begin{displayquote}
\texttt{install.packages("ggplot2",}
\texttt{repos="http://cran.us.r-project.org")}
\end{displayquote}

which results into this text in the pdf document:

install.packages("ggplot2", 
repos="http://cran.us.r-project.org")

I would like to move the 2nd line a bit to the right, this way:

install.packages("ggplot2", 
   repos="http://cran.us.r-project.org")

but I cannot find a way to insert some blank spaces near the word repos. I tried with \hspace{1cm}, with $\;\;\;$, with \indent, but nothing worked. Does anybody know how to insert these blank spaces?

Thank you

5
  • 1
    Have you tried \quad or \qquad?
    – Ingmar
    Jan 20 at 18:28
  • 1
    @Ingmar I just tried, it did not work. Thanks anyway Jan 20 at 18:32
  • or maybe \hpantom
    – riccs_0x
    Jan 20 at 18:32
  • 1
    @riccs_0x Do you mean \phantom? It worked but it removed the first letter of repos, that now became epos Jan 20 at 18:36
  • @DavideChicco.it, no I mean the \hphantom as far as I remember.
    – riccs_0x
    Jan 20 at 18:58
2

First of all, you have to end the first line with \\. Then \hspace*{1cm} (note the asterisk) will work.

\begin{displayquote}
\texttt{install.packages("ggplot2",}\\
\hspace*{1cm}\texttt{repos="http://cran.us.r-project.org")}
\end{displayquote}

Another solution:

\begin{verbatim}
install.packages("ggplot2",
    repos="http://cran.us.r-project.org")
\end{verbatim}

This solution allows you to add all kinds of funny characters that you cannot use directly as in \texttt.

enter image description here

\documentclass{article}
\usepackage{csquotes}
\begin{document}

\paragraph{displayquote}

\begin{displayquote}
\texttt{install.packages("ggplot2",}\\
\hspace*{1cm}\texttt{repos="http://cran.us.r-project.org")}
\end{displayquote}

\paragraph{verbatim, left-aligned}

\begin{verbatim}
install.packages("ggplot2",
     repos="http://cran.us.r-project.org")
\end{verbatim}

\paragraph{verbatim, shifted}

\begin{verbatim}
     install.packages("ggplot2",
          repos="http://cran.us.r-project.org")
\end{verbatim}

\end{document}

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.