3

The problem when I export the document to PDF there is some text at the end of the lines does not appear to the print page. How can I fix this?

\begin{verbatim}
//Add staff.php
<link href="../style.css" media="screen" rel="stylesheet" type="text/css" />
<form action="savestaff.php" method="post">
<center><h4><i class="icon-plus-sign icon-large"></i> Register Staffs</h4></center>
<hr>
<div id="ac">
<span>Staff Id : </span><input type="text" style="width:265px; height:30px;" 
name="Staffid" 
placeholder="Staff Id" 
Required/><br>
<span>First Name : </span><input type="text" style="width:265px; height:30px;" name="Fname" placeholder="Fname" Required/><br>
<span>Last Name : </span><input type="text" style="width:265px; height:30px;" name="Lname" placeholder="Lname" Required/><br>
<span>Gender : </span><input type="text" style="width:265px; height:60px;" name="Gender" placeholder="Gender" Required/><br>
<span>Date of birth : </span><input type="text" style="width:265px; height:30px;" name="DateOfBirth" placeholder="DateOfBirth" Required/><br>
<span>Phone Number : </span><input type="text" style="height:60px; width:265px;" name="PhNo" placeholder="PhNo" Required/><br>
<span>Email: </span><input type="date" style="width:265px; height:30px;" name="Email" placeholder="Email" Required/><br>
<span>Home Address : </span><input type="date" style="width:265px; height:30px;" name="HomeAddress" placeholder="HomeAddress" Required/><br>
<span>Staff Position : </span><input type="date" style="width:265px; height:30px;" name="position" placeholder="position" Required/><br>
<span>Staff Password : </span><input type="date" style="width:265px; height:30px;" name="password" placeholder="password" Required/><br>
<div style="float:right; margin-right:10px;">
<button class="btn btn-success btn-block btn-large" style="width:267px;"><i class="icon icon-save icon-large"></i> Save</button>
</div>
</div>
</form>
\end{verbatim}
  • Welcome to the site. The verbatim macro takes its line-feed from the input text, not the document margin (that is why it is verbatim). You could break up the long lines manually, or you could shrink the size of the verbatim listing easily enough. There may be some other similar environments (listings comes to mind) that may be able to automate the newline. – Steven B. Segletes Nov 10 '15 at 1:29
4

I'd recommend using the listings package for this; it's considerably more flexible. For example, you can specify \lstset{breaklines=true} in the preamble to prevent lines from overrunning the margins.

Here's a basic way to do it.

\documentclass{article}
\usepackage{listings}
\lstset{
    basicstyle=\footnotesize\ttfamily,
    % specifies that lines shouldn't overrun the margin
    breaklines=true
    % specified that, if possible, lines should be broken at whitespace
    breakatwhitespace=true 
}
\begin{document}
\begin{lstlisting}
//Add staff.php
<link href="../style.css" media="screen" rel="stylesheet" type="text/css" />
<form action="savestaff.php" method="post">

... rest of HTML snippet ... 

</div>
</div>
</form>
\end{lstlisting}
\end{document}

Here's what it will look like.

enter image description here

You can also make listings syntax-highlight this code for you, which might be useful. For example, suppose we change the preamble to this:

\documentclass[preview, margin=3cm]{standalone}
\usepackage{listings}
\usepackage{xcolor}
\lstset{
    basicstyle=\footnotesize\ttfamily,
    breaklines=true,
    breakatwhitespace=true,
    identifierstyle=\color[HTML]{CF000F},
    keywordstyle=\color[HTML]{0E723C},
    language=HTML,
    stringstyle=\color[HTML]{1A337B},
    showstringspaces=false
}

Then, you get colored ouput: enter image description here

There's lots more to explore; I found Wikibooks' article on listings to be a good introductory guide.

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.