简体   繁体   中英

How to reduce the separation from other text using LaTeX minted?

I want to use the minted package to give me syntax highlighting but it has a spacing of more than a centimeter.

Setting:

\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
\setlength{\headsep}{0pt}
\setlength{\topskip}{0pt}
\setlength{\topmargin}{0pt}
\setlength{\topsep}{0pt}
\setlength{\partopsep}{0pt}

does not help at all. Is there any way to reduce the spacing from the rest of the text?

minted internally uses the Verbatim environment from the fancyvrb package. In the documentation of the implementation, the following formula for the spaces is given:

 <topskip> = \\topsep + \\partopsep + \\parskip <botskip> = \\topsep + \\partopsep 

And

Except when in label or after nobreak, \\parskip is added with \\addvspace , so that net space is:

 MAX{\\topsep (+\\partopsep) + \\parskip , \\lastskip } 

(The usual \\@item works the same way.)

Hence, setting \\partopsep to some other value does the trick; I've tried it, and you need a negative value to remove the margin:

\setlength\partopsep{-\topsep}

This removes most of the space between the text body and the code. To get a distance of 0.5cm, add its distance to that:

\setlength\partopsep{-\topsep}
\addtolength\partopsep{-\parskip}
\addtolength\partopsep{0.5cm}

An implementation can be found in https://tex.stackexchange.com/a/19423

I don't see exactly want you want to do. Do you want to change the line spacing? If so you can use

\linespread{1.0}

and play a little bit around with the number in the parentheses.

The commands you have given as an example refer to the page environment. See the Wiki link for additional explanations and examples:

LaTeX Page Layout

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM