# How do i create a rectangle with parallel line inside it?

How to create rectangle with parallel line? Something likes this. The solution defines a rectangular shape of certain size. Then draw the two lines, respectively. Once the lines are drawn, put a node with rectangular shape over the two lines using [anchor=north west] at (x,y) to superimpose on the two lines. Adjust the minimum width=4cm if the lines are long. Edit: Inspired by Ignasi in the command below, the following two methods also achieve the same objective. Many thanks

Code

Method 1: use of fit

\documentclass[varwidth,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}

\tikzset{
s/.style={
draw, rectangle, minimum height=3cm, minimum width=5cm,
},
}
\begin{document}
\begin{tikzpicture}[
%    show background rectangle,
]
\draw (0,0) --node[midway,below](a){$\rho_1,\nu_1$} (3,0);
\draw (0,-1) --node[midway,below](b){$\rho_2,\nu_2$} (3,-1);
%\node[anchor=north west] at (-1,1) (){};
\node[fit=(a) (b),s] {};
\end{tikzpicture}
\end{document}


Method 2: use of show background rectangle

\documentclass[varwidth,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{fit,backgrounds}

\tikzset{
s/.style={
draw, rectangle, minimum height=3cm, minimum width=5cm,
},
}
\begin{document}
\begin{tikzpicture}[
show background rectangle,
]
\draw (0,0) --node[midway,below](a){$\rho_1,\nu_1$} (3,0);
\draw (0,-1) --node[midway,below](b){$\rho_2,\nu_2$} (3,-1);
%\node[anchor=north west] at (-1,1) (){};
%\node[fit=(a) (b),s] {};
\end{tikzpicture}
\end{document}


Original: use of anchor (method 3)

\documentclass[varwidth,border=10pt]{standalone}
\usepackage{tikz}

\tikzset{
s/.style={
draw, rectangle, minimum height=3cm, minimum width=4cm,
},
}
\begin{document}
\begin{tikzpicture}
\draw (0,0) --node[midway,below]{$\rho_1,\nu_1$} (2,0);
\draw (0,-1) --node[midway,below]{$\rho_2,\nu_2$} (2,-1);
\node[s,anchor=north west] at (-1,1) (){};
\end{tikzpicture}
\end{document}


## My Suggested Edit:

\documentclass[varwidth,border=10pt]{standalone}
\usepackage{tikz}

\tikzset{
s/.style={
draw, rectangle, minimum height=3cm, minimum width=4cm,
},
}
\begin{document}
\begin{tikzpicture}
\draw (-0.5,0.5) --node[midway,below]{$\rho_1,\nu_1$} (2.5,0.5);
\draw (-0.5,-1) --node[midway,below]{$\rho_2,\nu_2$} (2.5,-1);
\node[s,anchor=north west] at (-1,1) (){};
\end{tikzpicture}
\end{document} • You can also use fit to draw encompassing box, or just show background rectangle May 22 '14 at 18:07
• @Ignasi -- thank you so much for the insights. I have just tried them out and added them to the OP. May 22 '14 at 20:02
• @Jesse: Dear jesse thanks for helping me, a question please, how do change font of \rho and v ? regards May 23 '14 at 7:38
• @Jesse: Dear jesse thanks for helping me, a question please, how do change size(bigger) of \rho and v ? regards May 23 '14 at 7:57
• Hi, use \large, \Large, \LARGE \huge \HUGE of your choice right before the \rho and \nu May 23 '14 at 8:04

Here is a hint with PSTricks:

\begin{pspicture}[showgrid=false](3,2)
% THE FRAME
\psframe[linewidth=1.5\pslinewidth](3, 2)
% THE LINES
\psline{-}(0.5, 0.8)(2.5, 0.8)
\psline{-}(0.5, 1.5)(2.5, 1.5)
% THE LETTERS
\rput(1.5, 1.2){$\rho_1, v_1$}  % Or \nu, I don't know ^^
\rput(1.5, 0.5){$\rho_2, v_2$}
\end{pspicture} Just edit the coordinates of the lines and the text to fit your desire...

## Edit

As a community wiki tag attached, here is my contribution, simplifying the code.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}

\begin{document}
\begin{pspicture}[shortput=nab](3,2)
\psframe(3,2)
\pcline(.5,.8)(2.5,.8)_{$\rho_2, v_2$}
\pcline(0.5, 1.5)(2.5, 1.5)_{$\rho_1, v_1$}
\end{pspicture}
\end{document}


No fancy tricks; just a framed box with a tabular inside: \documentclass{article}
\begin{document}

\setlength{\fboxsep}{\baselineskip}%
\noindent
\fbox{\begin{tabular}{@{}c@{}}
\hline
\null\qquad$\rho_1,\nu_1$\qquad\null \\ \\
\hline
\null\qquad$\rho_2,\nu_2$\qquad\null
\end{tabular}}

\end{document}


I just use nested stacks here. The gap inside the box perimeter is 2ex, specified by \fboxsep. The 10pt is the gap between the two elements, and the 4pt is the gap between the text and the overline. The rule length is 15ex. All these dimensions can be tuned for your need.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\stackMath
\begin{document}
\fboxsep=2ex\fbox{%
\stackunder[10pt]{\stackon[4pt]{\rho_1,\,v_1}{\rule{15ex}{.4pt}}}%
{\stackon[4pt]{\rho_2,\,v_2}{\rule{15ex}{.4pt}}}%
}
\end{document} Here is a solution which uses only TeX primitives:

\def\inrule{\vrule width7em height.4pt}
\vbox{\hrule\hbox{\vrule\kern1em\vbox{\vskip1.1em\halign{\hfil$#$\hfil\cr
\inrule \cr
\rho_1, v_1\cr
\inrule \cr
\rho_2, v_2\cr}
\vskip.5em}\kern1em\vrule}\hrule
}