Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Given this, how can I add a border around?

\begin{ttfamily}
\begin{lstlisting}
g@g0001:~$ cd Desktop
g@g0001:~/Desktop$ cat script.sh

#!/bin/bash
echo $1 `date`

g@g0001:~/Desktop$ ./script.sh "hello"
hello Wed Dec 19 06:30:49 CET 2012

g@g0001:~/Desktop$ ./script.sh "`ls -la`"
total 244 drwxr-xr-x 2 g g 4096 2012-12-19 06:29
. drwxr-xr-x 34 g g 4096 2012-12-19 06:23
.. -rwxr-xr-x 1 g g 314 2012-11-24 12:06
25332.txt -rw------- 1 g g 1038 2008-01-15 18:59
Makefile -rw-r--r-- 1 g g 227981 2011-09-06 10:37
.pdf -rwxrwxrwx 1 g g 29 2012-12-18 18:16
script.sh Wed Dec 19 06:31:18 CET 2012
\end{ttfamily}

I tried \fbox but I get an error.

share|improve this question
3  
Do you know the option frame of package listings? You have an accept rate of 0%. That is rather low. Please visit your questions and upvote helpful answers. Accept the most helpful answer for you. That will bring people to answer further questions of you. Upvoting ans accepting is the way here to say "thank you". –  Kurt Dec 29 '12 at 23:15
4  
Since you have some responses for your other questions of which some have valid answers, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. –  Werner Dec 29 '12 at 23:23
    
Sorry about that. Once I tried to upvote but I got a message saying I couldn't just do that since my score was too low.. –  g9999 Dec 29 '12 at 23:26
    
@g9999 Upvoting is different from accepting. You can't upvote answers or questions until your reputation is less than 15 (it's a mild protection against abuses); accepting will help other users with similar problems in understanding what answer was the most useful to the questioner. –  egreg Dec 29 '12 at 23:34
    
@g9999 BTW, you can already upvote answers now that your reputation is greater than 15 :) –  hpesoj626 Dec 30 '12 at 1:06

1 Answer 1

Are you trying to achieve something like this?

% http://tex.stackexchange.com/questions/88564/how-can-i-add-borders
\documentclass[border=5,preview]{standalone}

\usepackage{listings}
\lstset{
basicstyle=\ttfamily,
frame=single
}
\begin{document}
\begin{lstlisting}
g@g0001:~$ cd Desktop
g@g0001:~/Desktop$ cat script.sh

#!/bin/bash
echo $1 `date`

g@g0001:~/Desktop$ ./script.sh "hello"
hello Wed Dec 19 06:30:49 CET 2012

g@g0001:~/Desktop$ ./script.sh "`ls -la`"
total 244 drwxr-xr-x 2 g g 4096 2012-12-19 06:29
. drwxr-xr-x 34 g g 4096 2012-12-19 06:23
.. -rwxr-xr-x 1 g g 314 2012-11-24 12:06
25332.txt -rw------- 1 g g 1038 2008-01-15 18:59
Makefile -rw-r--r-- 1 g g 227981 2011-09-06 10:37
.pdf -rwxrwxrwx 1 g g 29 2012-12-18 18:16
script.sh Wed Dec 19 06:31:18 CET 2012
\end{lstlisting}
\end{document}

enter image description here

Here, the frame was achieved with the frame option with value single. The default value is none. You can choose from other values: leftline, topline, bottomline, lines, or shadowbox. Also, you don't need to put your listings inside \begin{ttfamily}...\end{ttfamily} as this can be set by the option basicstyle. The font styles can be achieved through options among others basicstyle, keywordstyle, numberstyle, identifierstyle, commentstyle, etc. You can set these and more.

Consult the listings manual (specifically Section 4.6 and 4.11) by clicking on this link or by entering texdoc listings in your terminal. For a full set of frame options, see Section 4.11.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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