2

For some reason the listings package is breaking lines in the minimal working example below despite the fact that the breaklines=false option is set.

\documentclass{article}

\usepackage{listings}
\lstset{
  breaklines=false,
  basicstyle=\ttfamily
}

\begin{document}
\begin{lstlisting}
                                                  Number of obs   =       2239
                                                  Wald chi2(6)    =          .
Log pseudolikelihood = -1512.9798                 Prob > chi2     =          .

                                   (Std. Err. adjusted for 115 clusters in id)
------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
crra         |
       test1 |   .9284791   .1856117     5.00   0.000     .5646869    1.292271
       _cons |   1.203079   .7054548     1.71   0.088    -.1795867    2.585745
-------------+----------------------------------------------------------------
gamma        |
       _cons |   1.251066   .4030218     3.10   0.002     .4611582    2.040975
-------------+----------------------------------------------------------------
noise        |
      female |   6.967949   29.98527     0.23   0.816    -51.80211      65.738
       _cons |   46.31619          .        .       .            .           .
------------------------------------------------------------------------------
\end{lstlisting}
\end{document}

Screenshot:

enter image description here

1 Answer 1

3

Add columns=fullflexible, which works best when a monospaced font is used. You also want keepspaces.

\documentclass{article}

\usepackage{listings}
\lstset{
  basicstyle=\ttfamily,
  columns=fullflexible,
  keepspaces,
}

\begin{document}
\begin{lstlisting}
                                                  Number of obs   =       2239
                                                  Wald chi2(6)    =          .
Log pseudolikelihood = -1512.9798                 Prob > chi2     =          .

                                   (Std. Err. adjusted for 115 clusters in id)
------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
crra         |
       test1 |   .9284791   .1856117     5.00   0.000     .5646869    1.292271
       _cons |   1.203079   .7054548     1.71   0.088    -.1795867    2.585745
-------------+----------------------------------------------------------------
gamma        |
       _cons |   1.251066   .4030218     3.10   0.002     .4611582    2.040975
-------------+----------------------------------------------------------------
noise        |
      female |   6.967949   29.98527     0.23   0.816    -51.80211      65.738
       _cons |   46.31619          .        .       .            .           .
------------------------------------------------------------------------------
\end{lstlisting}
\end{document}

enter image description here

You should however compare it with the following realization:

\documentclass{article}

\usepackage{booktabs,siunitx}

\begin{document}

\begin{table}
\caption{A better one}
\medskip

\addtolength{\tabcolsep}{-2pt}
\begin{tabular}{
  @{}
  r
  S[table-format=2.7]
  S[table-format=2.7]
  S[table-format=1.2]
  S[table-format=1.3]
  S[table-format=-2.7]
  S[table-format=-2.6]
  @{}
}
\toprule
\multicolumn{7}{@{}c@{}}{%
  Log pseudolikelihood = \num{-1512.9798}\hfill
  \begin{tabular}[b]{@{}l@{${}={}$}S[table-format=4.0]@{}}
  Number of obs    & 2239 \\
  Wald $\chi^2(6)$ & {--} \\
  Prob $> \chi^2$  & {--} \\
  \end{tabular}%
}
\\[1ex]
\multicolumn{7}{@{}r@{}}{(Std.\ Err.\ adjusted for 115 clusters in id)}
\\
\midrule
& {Coef.}
& {\begin{tabular}{@{}c@{}}Robust\\Std.\ Err.\end{tabular}}
& {$z$}
& {$P>|z|$}
& \multicolumn{2}{c@{}}{95\% Conf.\ Interval}
\\
\midrule
\multicolumn{1}{@{}l}{crra}\\
test1  &   .9284791 &   .1856117 & 5.00 & 0.000 &    .5646869 &  1.292271 \\
\_cons &  1.203079  &   .7054548 & 1.71 & 0.088 &   -.1795867 &  2.585745 \\
\midrule
\multicolumn{1}{@{}l}{gamma}\\
\_cons &  1.251066  &   .4030218 & 3.10 & 0.002 &    .4611582 &  2.040975 \\
\midrule
\multicolumn{1}{@{}l}{noise}\\
female &  6.967949  & 29.98527   & 0.23 & 0.816 & -51.80211   & 65.738    \\
\_cons & 46.31619   &  {--}      & {--} & {--}  & {--}        & {--}      \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

2
  • You put way too much effort into this! In this particular case, I actually wanted the raw, verbatim output. Otherwise I would have put this in a proper table myself. Thank you very much for the extra effort!
    – RoyalTS
    Commented Mar 29, 2016 at 18:01
  • 2
    @RoyalTS I can't stand horrible tables. ;-)
    – egreg
    Commented Mar 29, 2016 at 18:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .