![逐字超出文本块](https://linux22.com/image/322603/%E9%80%90%E5%AD%97%E8%B6%85%E5%87%BA%E6%96%87%E6%9C%AC%E5%9D%97.png)
当我将文档导出为 PDF 时,打印页面上没有显示行尾的某些文本。我该如何修复此问题?
\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}
答案1
我建议使用这个listings
包来实现这一点;它非常灵活。例如,您可以\lstset{breaklines=true}
在序言中指定以防止行超出边距。
这是一个基本的方法。
\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}
它看起来是这样的。
您还可以让listings
此代码语法高亮,这可能会很有用。例如,假设我们将序言改为:
\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
}
我发现还有很多东西值得探索Wikibooks 上的文章listings
作为一个很好的入门指南。