1

I have the following long listing. I used an adjustbox to fit the lines and added [float=*] to the listing properties in order to fit it into two columns. I am using this template which is a two column based article. The problem is shown in the photo below. How to prevent this to happen?

MWE

   \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} 

enter image description here

EDIT

Based on the answer provided below, the result will be like this. That is the whole point of using adjustbox to let the listing to be adjusted in a box~!

enter image description here

EDIT 2

When I replace the answer of Zarko with the code in my original project, the adjustbox appears to be rendered as below:

enter image description here

EDIT 3 I have checked my original project and I have realized that the problem is caused due to the fact that I have another listing before it. I have edited MWE and added the first listing to it. Compiling new MWE will result into the following snapshot:

enter image description here

closed as unclear what you're asking by Zarko, Stefan Pinnow, Schweinebacke, TeXnician, Mico Jul 11 '17 at 20:19

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    seems like the float* isn't quite working, could you post a complete MWE with \begin{document} and all ? – Elad Den Jul 11 '17 at 10:51
  • 1
    @EladDen sure but you need to download the package as I mentioned within my question. – lonesome Jul 11 '17 at 10:53
  • 1
    No problem, as long as we have something we can compile and check :) – Elad Den Jul 11 '17 at 11:08
  • 1
    @EladDen take a look now, please. – lonesome Jul 11 '17 at 11:09
  • 1
    @Zarko but it will be limited to one column. I want it to occupy both column. Just like figure* or table*. – lonesome Jul 11 '17 at 11:22
1

There is no need for \adjustbox, the float=* should be in the lstlisting definition. It is a big float, so LaTeX pushes it to a page of its own. I used the floatbarrier just to show it is a floating float.

\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}

EDIT:

AND THE RESULT enter image description here

  • 1
    did you even compile it? if so, you will notice the reason for using adjustbox.however, I have updated my question. – lonesome Jul 11 '17 at 12:46
  • 1
    I did compile it, and it worked out just fine. Try my MWE AS IS, see what happens, then put it in your code, there might be something else there – Elad Den Jul 12 '17 at 8:30

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