逐字超出文本块

逐字超出文本块

当我将文档导出为 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作为一个很好的入门指南。

相关内容