6

How to create rectangle with parallel line?

enter image description here

3

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.

enter image description here

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} 

enter image description here

5
  • You can also use fit to draw encompassing box, or just show background rectangle
    – Ignasi
    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.
    – Jesse
    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
    – tanha
    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
    – tanha
    May 23 '14 at 7:57
  • Hi, use \large, \Large, \LARGE \huge \HUGE of your choice right before the \rho and \nu
    – Jesse
    May 23 '14 at 8:04
3

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}

Try with PSTricks

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}
3

No fancy tricks; just a framed box with a tabular inside:

enter image description here

\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}
2

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}

enter image description here

2

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
}

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.