2

I have a little problem. I use parbox and textblock to position my text in front of a more or less complicated background-image.

Now I would like to highlight my parboxes to see if all margins are set correctly. However, I still want to see the background through, only have a red (potentially dashed) frame around and, most importantly, I want to be able to switch this frame off with a command in the preamble without any movement of my content.

I tried fbox and fcolorbox and was in both cases not even able to achieve non-moving content - not speaking of the other things I would like to achieve.

Any ideas how to implement something like that?

Thanks a lot in advance!

Edit:

Sorry about that. Here some example code

\documentclass[fontsize=10pt]{scrartcl}

\usepackage{lipsum}
\usepackage[overlay]{textpos}
\usepackage{color}

%% BACKGROUND  <<------ activate for actual background
%
%\usepackage{bophook}
%\usepackage{xcolor}
%\usepackage{tikz}
%
%\definecolor{dark}{RGB}{25,49,83}
%\colorlet{light}{dark!10}
%
%\newcommand{\topbar}{\draw[fill=dark, draw=none] (0,0) rectangle (216mm,-83mm);}
%\newcommand{\sidepanel}{\draw[fill=light, draw=none] (13mm,-23mm) rectangle (83mm,-280mm);}
%\newcommand{\footer}{%
%   \draw[fill=light, draw=none] (0mm,-303mm) rectangle (216mm,-290mm);%
%   \filldraw [fill=dark, draw=none] (184mm,-292.5mm)  coordinate (GeneralStart) -- ++(0,0) -- ++(+3.2,0) -- ++(0,-1.05) -- ++(-4.0,0) -- cycle;}
%
%\newcommand{\setbg}[1]{%
%   \AtBeginPage{%
%       \begin{tikzpicture}[remember picture,overlay]
%       \node[xshift=-108mm, yshift=151.5mm] at (current page.center)
%       {%
%           \begin{tikzpicture}[remember picture, overlay]%
%           #1
%           \end{tikzpicture}
%       };
%   \end{tikzpicture}
%}}


% HIGHLIGHTING


\newcommand{\lbox}[1]{\color{red}\fbox{ \normalcolor{#1}}}
%\renewcommand{\lbox}[1]{#1}  <<------- TOGGLE THIS


\begin{document}

%\setbg{\topbar\sidepanel\footer} <<------ activate for actual background

\begin{textblock*}{187mm}(-30mm,45mm)
    \lbox{%
        \parbox[c][187mm][c]{62mm}{%
            \lipsum[1-2]%
        }}
    \end{textblock*}

\end{document}

Toggle the marked content. As you will see, the text shifts, unfortunately. The only thing I actually want is to see on paper where my parbox is. The text shall not react to the box.

2

You can add a frame around the content using the adjustbox package. All you need is to remove the extra space by a matching negative margin. So you need to use \adjustbox{cfbox=red, margin=-\fboxrule-\fboxsep}{...}. Check the adjustbox manual for details if you want to know more.

\documentclass[fontsize=10pt]{scrartcl}
\usepackage{adjustbox}

\usepackage{lipsum}
\usepackage[overlay]{textpos}
\usepackage{color}

%% BACKGROUND  <<------ activate for actual background
\newif\ifbackground

\backgroundtrue

\ifbackground
\usepackage{bophook}
\usepackage{xcolor}
\usepackage{tikz}

\definecolor{dark}{RGB}{25,49,83}
\colorlet{light}{dark!10}

\newcommand{\topbar}{\draw[fill=dark, draw=none] (0,0) rectangle (216mm,-83mm);}
\newcommand{\sidepanel}{\draw[fill=light, draw=none] (13mm,-23mm) rectangle (83mm,-280mm);}
\newcommand{\footer}{%
   \draw[fill=light, draw=none] (0mm,-303mm) rectangle (216mm,-290mm);%
  \filldraw [fill=dark, draw=none] (184mm,-292.5mm)  coordinate (GeneralStart) -- ++(0,0) -- ++(+3.2,0) -- ++(0,-1.05) -- ++(-4.0,0) -- cycle;}

\newcommand{\setbg}[1]{%
   \AtBeginPage{%
      \begin{tikzpicture}[remember picture,overlay]
       \node[xshift=-108mm, yshift=151.5mm] at (current page.center)
       {%
           \begin{tikzpicture}[remember picture, overlay]%
          #1
           \end{tikzpicture}
       };
   \end{tikzpicture}
}}
\fi

% HIGHLIGHTING

\newcommand{\lbox}{\adjustbox{cfbox=red, margin=-\fboxrule-\fboxsep}}
%\renewcommand{\lbox}{\fbox}
%\renewcommand{\lbox}[1]{#1} % <<------- TOGGLE THIS


\begin{document}
\ifbackground
\setbg{\topbar\sidepanel\footer} %<<------ activate for actual background
\fi

\begin{textblock*}{187mm}(-30mm,45mm)
    \lbox{%
        \parbox[c][187mm][c]{62mm}{%
            \lipsum[1-2]%
        }}
    \end{textblock*}

\end{document}

PS: Also note the usage of an custom \if... switch. You should not use % to deactivate a large part of code.

  • Also, the \parbox can be moved into the \adjustbox call using \adjustbox{minipage=[c][187mm][c]{62mm},...}{...} etc. – Martin Scharrer Dec 18 '17 at 14:29
0

In case someone wants to do something similar in the future, that is what I finally came up with.

\newcommandtwoopt{\cbox}[7][t][]{%
    \begin{textblock*}{#5}(#3,#4)%
        \adjustbox{#2, minipage=[#1][#6][#1]{#5}, cfbox=red 0pt 0.5pt}{#7}%
    \end{textblock*}%
}

%\cbox[minipagealignment][adjustboxoptions]{xpos}{ypos}{width}{height}{content}

By switching the 0.5pt and 0pt, which could be implemented as a package option or with an if-clause), one can switch the boxes on and off without movement of the content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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