[Tex/LaTex] draw a grid in the foreground


I'm trying to follow this example on how to draw a background grid so I can easily connect arrows, but it draws the (non-transparent) picture on top of the grid making it hard to use. I want to draw the grid in the foreground, how can I do that?

Best Answer

You can temporarily use opacity=.5 for the node where you insert the picture:

\node [inner sep=0pt,above right,opacity=.5]   %%% <--- here

When you are done, simply make opacity = 1 or delete it.

Full code:

\documentclass{beamer} %


% For every picture that defines or uses external nodes, you'll have to
% apply the 'remember picture' style. To avoid some typing, we'll apply
% the style to all pictures.
\tikzstyle{every picture}+=[remember picture]
\tikzstyle{na} = [baseline=-.5ex]


\frametitle{Daniell's pile, saline bridge version}

        % define source coordinates
            \item Anode \tikz[na] \coordinate (s-anode);
            \item Cathode \tikz[na] \coordinate (s-cathode);
            \item Saline bridge \tikz[na] \coordinate (s-bridge);

        % Use a background grid to make it easier to find coordinates
        % When the coordinates have been found, remove the
        % 'show background grid' option.
        \tikzstyle{background grid}=[draw, black!50,step=.5cm]
        \begin{tikzpicture}[show background grid]
            % Put the graphic inside a node. This makes it easy to place the
            % graphic and to draw on top of it.
            % The above right option is used to place the lower left corner
            % of the image at the (0,0) coordinate.            
            \node [inner sep=0pt,above right,opacity=.5]
            % show origin
            \fill (0,0) circle (2pt);
            % define destination coordinates
            \path (0.7,2) coordinate (cathode)
                  (2,1.8) coordinate (bridge)
                  (2.75,2.5) coordinate (anode);

% define overlays
% Note the use of the overlay option. This is required when
% you want to access nodes in different pictures.
        \path[->,red,thick] (s-anode) edge [bend left] (anode);
        \path[->,blue,thick] (s-cathode) edge [bend left] (cathode);
        \path[->,red,thick] (s-bridge) edge [out=0, in=-90] (bridge);



enter image description here

Or using a scope to draw them after including image.

        \node [inner sep=0pt,above right]
        \path (0.7,2) coordinate (cathode)
            (2,1.2) coordinate (bridge)
            (2.75,2.5) coordinate (anode);
        \draw (current bounding box.south west)
                    grid [step=0.5cm] (current bounding box.north east);

enter image description here

PS: I have used example-image from mwe package. Change it with your picture.

Related Question