0

I would like to fit the long string (as it is labelled url in the json file) inside the box without overflowing. As far as I understand, breaklines option only helps when strings consist of separated words. How about the longer words as in url scenario ? In the example, how can I split the url into more lines in order to fit them into the page or preferably inside the box ?

\documentclass{article}

\usepackage{floatrow}
\usepackage[newfloat]{minted}%
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Data Format}

\begin{document}

    \begin{listing}[H]    
        \inputminted[frame=lines,
                       framesep=2mm,
                       fontsize=\footnotesize,
                       linenos=true,
                       breaklines=true,
                       xleftmargin=21pt,
                       tabsize=1]{json}{code/test.json} 
        \label{list:bbbbbbbbbb}
    \end{listing}

\end{document}

Example content of the test file: (test.json)

{  
    "cID"               : 1,
    "test"              : "aaaaaaaaaaaaaaaa          bbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccccc",
    "url"               : "http://www.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccccccc.com"
}

It generates overflow for the url field: enter image description here

1 Answer 1

3

You can add also option breakanywhere=true (default value is false, thats why it is not active right away). Refer to page 15 and forward in fvextra pacakge documentation (same author as minted, and minted is using this package behind the scenes).

This option can also be set globaly. You might be also interested in command \breakanywheresymbolpreand simillar (refer to docs).

Heres the solution:

\documentclass{article}

\usepackage{floatrow}
\usepackage[newfloat]{minted}%
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Data Format}

\begin{document}

    \begin{listing}[H]    
        \inputminted[frame=lines,
                       framesep=2mm,
                       fontsize=\footnotesize,
                       linenos=true,
                       breaklines=true,
                       breakanywhere=true,
                       xleftmargin=21pt,
                       tabsize=1]{json}{code/test.json} 
        \label{list:bbbbbbbbbb}
    \end{listing}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .