Graphics, Figures & TablestikZ | Filled Rectangle with Border

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

tikZ | Filled Rectangle with Border

Post by psionman »

I would like to draw a black rectangle filled in light gray

Code: Select all

\fill[draw=black,color=lightgray] (1.5,4) rectangle (3.5,4.5);
This fills it, but doesn't draw the outline.

What should I do?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Filled Rectangle with Border

Post by localghost »

Please get used to always providing a minimal example to give an adequate problem description.
psionman wrote:[…] What should I do?
Read the pgf/tikZ user guide, which suggests another approach.

Code: Select all

\filldraw[draw=black,fill=lightgray] (1.5,4) rectangle (3.5,4.5);

Thorsten
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

Re: tikZ | Filled Rectangle with Border

Post by psionman »

Thanks, filldraw seems to give the same effect as fill. I still don't get the black outline
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: tikZ | Filled Rectangle with Border

Post by localghost »

Works fine for me. For more specific help see the links in my last reply.
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

tikZ | Filled Rectangle with Border

Post by psionman »

Here is a simple document. When I compile it I get no black outline, only the gray rectangle.

Code: Select all

\documentclass[11pt]{article}
\usepackage{tikz}

\begin{document}
  \begin{figure}[!ht]
    \begin {center}
      \begin{tikzpicture}
        \filldraw[draw=black,color=lightgray] (1,1) rectangle (3,3);
      \end{tikzpicture}
    \end{center}
  \end{figure}
\end{document}
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Filled Rectangle with Border

Post by localghost »

You should read more carefully what people write to you. As I suggested earlier, you need another syntax.

Code: Select all

\filldraw[draw=black,fill=lightgray] (1.5,4) rectangle (3.5,4.5);
Pay special attention to the options and compare with your version.

And by the way, you should not use the center environment here due to unwanted vertical space. Simply replace by the \centering command.
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

Re: tikZ | Filled Rectangle with Border

Post by psionman »

Thank you localghost

I apologise for causing your ire; I really did not see the difference. I do now and appreciate your help
Post Reply