
我有以下長列表。我使用 來adjustbox
適應線條並添加[float=*]
到列表屬性中,以便將其適應兩列。我在用這模板是一篇基於兩欄的文章。問題如下圖所示。如何防止這種情況發生?
微量元素
\documentclass{comjnl}
\usepackage{lipsum}
\usepackage{listings}
\usepackage{adjustbox}
\usepackage{url}
\usepackage{amsmath}
\usepackage{cuted}
\usepackage{hyperref}
\shortauthors{jd}
\begin{document}
\lipsum[50]
\lstset{
frame = single}
\begin{lstlisting}[caption={Regular expression used to extract links within HTML code of Web pages},label=Pattern,linewidth=12cm]
"https?://(?:www\\.)?[^\\n<>\"]+(?:\"[^<]*>([^<]*))?"
\end{lstlisting}
\lipsum[50]
\begin{strip}
\centering
\centering
\adjustbox{width=\textwidth, frame}{
\begin{lstlisting}[caption={A demonstration of a hierarchical XML file used in this experiment to evaluate our framework.},label=Layers,linewidth=20cm][float=*]
<?xml version="1.0" encoding="UTF-8"?>
<crawledURLs>
<URL adr="http://www.cs.tsinghua.edu.cn/publish/csen/index.html" id="0" info="">
<URL adr="http://www.tsinghua.edu.cn title=" id="1" info=""/>
-<URL adr="http://ss.cs.tsinghua.edu.cn" id="2" info="2017 Deep Learning Summer School">
<url ADR="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,300italic,400italic,700italic" ID="0" INFO=""/>
<url ADR="http://fontawesome.io/examples/ --" ID="1" INFO=""/>
<url ADR="http://www.cs.tsinghua.edu.cn/publish/csen/index.html" ID="2" INFO=""/>
<url ADR="http://www.tsinghua.edu.cn/publish/newthuen/newthuen_cnt/about-th/about-1.html" ID="3" INFO=""/>
</URL>
-<URL adr="http://thu-cmu.cs.tsinghua.edu.cn" id="3" info="Tsinghua-CMU Double Master Degree Progra...">
<url ADR="http://tv.tsinghua.edu.cn/folder1/folder20/2011/04/2011-04-215.html" ID="1" INFO=""/>
<url ADR="http://tv.tsinghua.edu.cn/folder1/folder20/2011/04/2011-04-215.html" ID="2" INFO="Tsinghua University Introduction"/>
<url ADR="http://www.tudou.com/programs/view/guyM0hdQNi4/?phd=99" ID="3" INFO=""/>
<url ADR="http://tv.tsinghua.edu.cn/folder1/folder20/2011/04/2011-04-215.html" ID="4" INFO="Campus Tour"/>
<url ADR="http://www.cs.tsinghua.edu.cn/" ID="5" INFO="DCST"/>
<url ADR="http://www.cmu.edu/index.shtml" ID="6" INFO="Carnegie Mellon University"/>
<url ADR="http://www.cs.tsinghua.edu.cn/" ID="7" INFO="Tsinghua CS Department"/>
<url ADR="http://www.cmu.edu/index.shtml" ID="8" INFO="CMU"/>
<url ADR="http://www.tsinghua.edu.cn/publish/th/index.html" ID="9" INFO="Tsinghua University"/>
</URL>
-<URL adr="http://ac.cs.tsinghua.edu.cn" id="4" info="Advanced Computing Master Program">
<url ADR="https://fonts.googleapis.com/icon?family=Material+Icons" ID="0" INFO=""/>
<url ADR="http://gradadmission.tsinghua.edu.cn" ID="1" INFO="Apply Now"/>
<url ADR="http://gradadmission.tsinghua.edu.cn" ID="2" INFO="Apply Now"/>
<url ADR="http://gradadmission.tsinghua.edu.cn" ID="3" INFO="Apply"/>
<url ADR="http://clem109.com" ID="4" INFO="clem109"/>
</URL>
<URL adr="http://www.csai.tsinghua.edu.cn/homepage.shtm" id="5" info="State Key Lab of Intelligence Techonoly ..."/>
<URL adr="http://media.cs.tsinghua.edu.cn/en/" id="6" info="Institute of HCI & Media Integration"/>
-<URL adr="http://soft.cs.tsinghua.edu.cn/English/index.html" id="7" info="Institute of Computer Software">
<url ADR="http://dbgroup.cs.tsinghua.edu.cn" ID="1" INFO="Data Engineering"/>
<url ADR="http://keg.cs.tsinghua.edu.cn" ID="2" INFO="Knowledge Engineering"/>
<url ADR="http://166.111.68.91" ID="3" INFO="Design Automation of Computer and VLSI Circuits"/>
<url ADR="http://vis.cs.tsinghua.edu.cn" ID="4" INFO="Visualization and Computer Graphics"/>
<url ADR="http://soft.cs.tsinghua.edu.cn/soft/" ID="5" INFO="Software Engineering and System Software"/>
<url ADR="http://dbgroup.cs.tsinghua.edu.cn" ID="6" INFO="Data Engineering"/>
<url ADR="http://keg.cs.tsinghua.edu.cn" ID="7" INFO="Knowledge Engineering"/>
<url ADR="http://166.111.68.91" ID="8" INFO="Design Automation of Computer and VLSI Circuit"/>
<url ADR="http://vis.cs.tsinghua.edu.cn" ID="9" INFO="Visualization Technology and Computer Graphics"/>
</URL>
<URL adr="http://network.cs.tsinghua.edu.cn" id="8" info="Institute of Computer Networks"/>
</URL>
</crawledURLs>
\end{lstlisting}
}
\end{strip}
\lipsum[50]
\lipsum[50]
\lipsum[50]
\lipsum[50]
\lipsum[50]
\end{document}
編輯
根據下面提供的答案,結果將是這樣的。這就是使用adjustbox讓listing在一個盒子裡調整的全部意義啦~!
編輯2
當我用原始項目中的程式碼取代 Zarko 的答案時,調整框顯示如下:
編輯3 我檢查了我的原始項目,我意識到問題是由於我之前有另一個清單而引起的。我已經編輯了 MWE 並向其中添加了第一個清單。編譯新的 MWE 將產生以下快照:
答案1
不需要\adjustbox
,float=*
應該在 lstlisting 定義中。它是一個很大的浮動體,因此 LaTeX 將其推送到自己的頁面。我使用 floatbarrier 只是為了表明它是一個浮動浮動。
\documentclass{comjnl}
\usepackage{lipsum}
\usepackage{listings}
\usepackage{placeins}
%\usepackage{adjustbox}
\usepackage{url}
\usepackage{amsmath}
\usepackage{hyperref}
\shortauthors{jd}
\begin{document}
\lipsum
\lipsum[1-3]
\lstset{frame = single,
language=XML,
framexleftmargin=10pt,
basicstyle=\footnotesize\ttfamily,
breaklines=true}
\begin{lstlisting}[caption={A demonstration of a hierarchical XML file used in this experiment to evaluate our framework.},label=Layers,float=*]
% <?xml version="1.0" encoding="UTF-8"?>
<crawledURLs>
<URL adr="http://www.cs.tsinghua.edu.cn/publish/csen/index.html" id="0" info="">
<URL adr="http://www.tsinghua.edu.cn title=" id="1" info=""/>
-<URL adr="http://ss.cs.tsinghua.edu.cn" id="2" info="2017 Deep Learning Summer School">
<url ADR="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,300italic,400italic,700italic" ID="0" INFO=""/>
<url ADR="http://fontawesome.io/examples/ --" ID="1" INFO=""/>
<url ADR="http://www.cs.tsinghua.edu.cn/publish/csen/index.html" ID="2" INFO=""/>
<url ADR="http://www.tsinghua.edu.cn/publish/newthuen/newthuen_cnt/about-th/about-1.html" ID="3" INFO=""/>
</URL>
-<URL adr="http://thu-cmu.cs.tsinghua.edu.cn" id="3" info="Tsinghua-CMU Double Master Degree Progra...">
<url ADR="http://tv.tsinghua.edu.cn/folder1/folder20/2011/04/2011-04-215.html" ID="1" INFO=""/>
<url ADR="http://tv.tsinghua.edu.cn/folder1/folder20/2011/04/2011-04-215.html" ID="2" INFO="Tsinghua University Introduction"/>
<url ADR="http://www.tudou.com/programs/view/guyM0hdQNi4/?phd=99" ID="3" INFO=""/>
<url ADR="http://tv.tsinghua.edu.cn/folder1/folder20/2011/04/2011-04-215.html" ID="4" INFO="Campus Tour"/>
<url ADR="http://www.cs.tsinghua.edu.cn/" ID="5" INFO="DCST"/>
<url ADR="http://www.cmu.edu/index.shtml" ID="6" INFO="Carnegie Mellon University"/>
<url ADR="http://www.cs.tsinghua.edu.cn/" ID="7" INFO="Tsinghua CS Department"/>
<url ADR="http://www.cmu.edu/index.shtml" ID="8" INFO="CMU"/>
<url ADR="http://www.tsinghua.edu.cn/publish/th/index.html" ID="9" INFO="Tsinghua University"/>
</URL>
-<URL adr="http://ac.cs.tsinghua.edu.cn" id="4" info="Advanced Computing Master Program">
<url ADR="https://fonts.googleapis.com/icon?family=Material+Icons" ID="0" INFO=""/>
<url ADR="http://gradadmission.tsinghua.edu.cn" ID="1" INFO="Apply Now"/>
<url ADR="http://gradadmission.tsinghua.edu.cn" ID="2" INFO="Apply Now"/>
<url ADR="http://gradadmission.tsinghua.edu.cn" ID="3" INFO="Apply"/>
<url ADR="http://clem109.com" ID="4" INFO="clem109"/>
</URL>
<URL adr="http://www.csai.tsinghua.edu.cn/homepage.shtm" id="5" info="State Key Lab of Intelligence Techonoly ..."/>
<URL adr="http://media.cs.tsinghua.edu.cn/en/" id="6" info="Institute of HCI & Media Integration"/>
-<URL adr="http://soft.cs.tsinghua.edu.cn/English/index.html" id="7" info="Institute of Computer Software">
<url ADR="http://dbgroup.cs.tsinghua.edu.cn" ID="1" INFO="Data Engineering"/>
<url ADR="http://keg.cs.tsinghua.edu.cn" ID="2" INFO="Knowledge Engineering"/>
<url ADR="http://166.111.68.91" ID="3" INFO="Design Automation of Computer and VLSI Circuits"/>
<url ADR="http://vis.cs.tsinghua.edu.cn" ID="4" INFO="Visualization and Computer Graphics"/>
<url ADR="http://soft.cs.tsinghua.edu.cn/soft/" ID="5" INFO="Software Engineering and System Software"/>
<url ADR="http://dbgroup.cs.tsinghua.edu.cn" ID="6" INFO="Data Engineering"/>
<url ADR="http://keg.cs.tsinghua.edu.cn" ID="7" INFO="Knowledge Engineering"/>
<url ADR="http://166.111.68.91" ID="8" INFO="Design Automation of Computer and VLSI Circuit"/>
<url ADR="http://vis.cs.tsinghua.edu.cn" ID="9" INFO="Visualization Technology and Computer Graphics"/>
</URL>
<URL adr="http://network.cs.tsinghua.edu.cn" id="8" info="Institute of Computer Networks"/>
</URL>
</crawledURLs>
\end{lstlisting}
\FloatBarrier
\lipsum[50]
\lipsum[50]
\lipsum[50]
\lipsum[50]
\lipsum[50]
\end{document}
編輯: