7

May be this is a very strange question. But I found this property is very useful to control the overlap element.

So I wonder if latex own this property as HTML div.

Do you have any better idea to solve the overlap problem. Sometime, I need to push some element back.

update:the MWE code



\documentclass{article}

\usepackage{listings}
\usepackage{courier}
\usepackage{caption}
\usepackage{xcolor} 
\usepackage{calc}

\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\parbox{\textwidth}{\colorbox{gray}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,
labelfont=white,
textfont=white,
singlelinecheck=false,
margin=0pt,
font={bf,footnotesize}
}

\newlength\tdima
\setlength\tdima{ \fboxsep+\fboxrule}

\lstset{
         basicstyle=\small\tt,
         tabsize=2,                  
         extendedchars=true,         
         breaklines=true,           
         mathescape,
         escapeinside={\%*}{*)},        
         showspaces=false,          
         showtabs=false,             
         showstringspaces=false,      
         columns=flexible,
         xleftmargin=\tdima,
         framextopmargin= 10pt,
         framexbottommargin=10pt,
         float=tp,                            % float setting
         frame=single,
}%

\begin{document}
\begin{lstlisting}[caption=overlap]
using namespace std;
int main(void)
{
    return 0;
}
\end{lstlisting}
\end{document}  


Output:

enter image description here

The caption overlap with the frame. And I want to push the caption back. Let the frame cover it. I don't want to use the \vskip to fine tuning the caption position.

3
  • 2
    Please give a minimal working example (MWE) where you want to control such an overlapping.
    – bodo
    Jun 22, 2012 at 18:09
  • @canaaerus please take a look at the revised edition question
    – pythonee
    Jun 23, 2012 at 7:21
  • I guess adding another \colorbox with a white background around the code should be the way to go, although I don't know how to achieve this with lstlisting. (As you can see the border is already in front of the label.) Maybe just adding backgroundcolor=\color{white} will do it.
    – bodo
    Jun 23, 2012 at 7:22

1 Answer 1

6

Add a dimension to \fboxsep, as follows:

  \DeclareCaptionFormat{listing}{\fboxsep=1.2pt....

enter image description here

4
  • how do you figure out the 1.2pt
    – pythonee
    Jun 24, 2012 at 3:00
  • @pythonee Newton–Raphson's method:) i.e., it looked that much and I tried it out, didn't want to read through the code. Jun 24, 2012 at 3:26
  • We usually name it as "trial and error" method. Jun 26, 2012 at 17:09
  • 1
    This doesn't actually answer the question. \fboxsep is a specific solution to the specific problem that OP had, it doesn't appear to be in any way related to z-index. Sep 22, 2019 at 21:45

You must log in to answer this question.

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