7

I want to draw a split with diffrent blocks inside each one there is the block index.

Since I am new to LaTeX, I tried to use

\fbox{$b_{0}$}\fbox{$b_{1}$}\fbox{$b_{2}$}%
\fbox{$..........................$}%
\fbox{$b_{S.t -1}$}\fbox{$b_{s.t}$} 

However, this gives boxes of different sizes. Is there any other suggestion.

4 Answers 4

11

EDITED to use LaTeX101 construct \framebox{}, instead of \fbox{\makebox{}} (D'oh!).

enter image description here

Use a \framebox instead of an \fbox, since it allows a box width to be specified. In this example, I choose 1 inch size and center alignment within the box. That is changed for the last example to left alignment.

\documentclass{article}
\newcommand\fxbox[1]{\framebox[1in][c]{#1}}
\parskip 1em\parindent 0in
\begin{document}
ORIGINAL:\\
\fbox{$b_{0}$}\fbox{$b_{1}$}\fbox{$b_{2}$}\fbox{$........................$%
  }\fbox{$b_{S.t -1}$}\fbox{$b_{s.t}$} 

UNIFORM WIDTH (center alignment):\\
\fxbox{$b_{0}$}\fxbox{$b_{1}$}\fxbox{$b_{2}$}\fxbox{$........................$%
  }\fxbox{$b_{S.t -1}$}\fxbox{$b_{s.t}$} 

\renewcommand\fxbox[1]{\framebox[1in][l]{\strut#1}}

UNIFORM WIDTH \& HEIGHT (left alignment):\\
\fxbox{$b_{0}$}\fxbox{$b_{1}$}\fxbox{$b_{2}$}\fxbox{$........................$%
  }\fxbox{$b_{S.t -1}$}\fxbox{$b_{s.t}$} 

\end{document}

enter image description here

You'll also note in the middle image that the vertical height of the boxes are a different, because of the height/depth of the content. If you would like those the same, you could define \fxbox as in the third example

\newcommand\fxbox[1]{\framebox[1in][l]{\strut#1}}

The \strut will extend the vertical box to the full line-height extent.

8
  • I don't want the boxes to have any space between them, to give an impression of a split divided to boxes
    – rima101
    Aug 30, 2013 at 11:24
  • 2
    \fbox{\makebox is \framebox Aug 30, 2013 at 11:25
  • 1
    What is LaTeX101 ?
    – Daniel
    Aug 30, 2013 at 12:01
  • 2
    @Daniel *anything*101 is an idiomatic expression in American English signifying the first course in a college sequence, or more generally the most elementary concept. Seeing as \framebox is on p.98 of Lamport's text, it is somewhat embarrassing to not recall it in my sleep. Aug 30, 2013 at 12:10
  • 3
    @Daniel I suppose I should either not use idioms for an international audience or clarify. To that end, "D'oh" is the expression used by American TV animated character Homer Simpson, upon realizing that he made an elementary mistake. (see edit) Aug 30, 2013 at 13:40
4

A TikZ solution:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
    \begin{tikzpicture}[
        every node/.style={
            draw,minimum width=1in,
            text height=1.75ex,
            text depth=0.5ex,
        },
        node distance=-\pgflinewidth,
    ]
        \node (b 0) {$b_0$};
        \node (b 1) [right=of b 0] {$b_1$};
        \node (b 2) [right=of b 1] {$b_2$};
        \node (dots) [right=of b 2] {.\,.\,.\,.\,.\,.\,.\,.};
        \node (b St-1) [right=of dots] {$b_{S.t -1}$};
        \node (b St) [right=of b St-1] {$b_{S.t}$};
    \end{tikzpicture}
\end{document}

some boxes

I used the every node style to let all nodes in the picture have the same width and hight, and draw the border. You can delete the lines with text depth and text height to let the nodes have their natural height. The node distance is set to the line width of the border, so between the nodes it looks like they share the line.

2
  • 1
    The text in the nodes are on different baselines (evident for the dots node, but the others might also differ). I'd suggest adding something like text height=1.5ex,text depth=.25ex to the node style to amend this. (This is kind of like adding a strut of height 1.5ex and depth 0.25ex to every text node.) [See further TikZ & PGF Manual for Version 2.1, $5.1 (pp 60-62)].
    – Johan_E
    Aug 30, 2013 at 14:40
  • @Johan_E: That’s a good idea, didn’t thought about that … :-)
    – Tobi
    Aug 30, 2013 at 14:45
4

Two solutions.

(1) The width is set to the widest entry, but an optional argument is provided for modifying it by addition. A second optional argument (in parentheses) is the inner alignment, default center.

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\rimatightboxes}{ O{0pt} D(){c} m }
 {
  \rima_tightboxes:nnn { #1 } { #2 } { #3 }
 }

\seq_new:N \l_rima_input_seq
\seq_new:N \l_rima_boxes_seq
\dim_new:N \l_rima_width_dim
\box_new:N \l_rima_entry_box

\cs_new_protected:Npn \rima_tightboxes:nnn #1 #2 #3
 {
  \seq_set_split:Nnn \l_rima_input_seq { , } { #3 }
  \dim_zero:N \l_rima_width_dim
  \seq_map_inline:Nn \l_rima_input_seq
   {
    \str_if_eq:nnF { ##1 } { \dots }
     {
      \hbox_set:Nn \l_rima_entry_box { $##1$ }
      \dim_set:Nn \l_rima_width_dim
       { \dim_max:nn { \l_rima_width_dim } { \box_wd:N \l_rima_entry_box } }
     }
   }
  \dim_add:Nn \l_rima_width_dim { (#1 + \fboxsep) * 2}
  \seq_set_map:NNn \l_rima_boxes_seq \l_rima_input_seq
   {
    \str_if_eq:nnTF { ##1 } { \dots }
     {
      \exp_not:n { \framebox[\l_rima_width_dim][#2] { \strut\dotfill } }
     }
     {
      \exp_not:n { \framebox[\l_rima_width_dim][#2] { \strut$##1$ } }
     }
   }
  \seq_use:Nn \l_rima_boxes_seq { \kern-\fboxrule }
 }
\ExplSyntaxOff

\begin{document}

\rimatightboxes{b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\bigskip

\rimatightboxes(l){b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\bigskip

\rimatightboxes[3pt]{b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\bigskip

\rimatightboxes[3pt](r){b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\end{document}

enter image description here

(2) The width is set via an optional argument (default 0.5in). A second optional argument (in parentheses) is the inner alignment, default center.

\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\rimaboxes}{ O{0.5in} D(){c} m }
 {
  \rima_boxes:nnn { #1 } { #2 } { #3 }
 }

\seq_new:N \l_rima_input_seq
\seq_new:N \l_rima_boxes_seq

\cs_new_protected:Npn \rima_boxes:nnn #1 #2 #3
 {
  \seq_set_split:Nnn \l_rima_input_seq { , } { #3 }
  \seq_set_map:NNn \l_rima_boxes_seq \l_rima_input_seq
   {
    \str_if_eq:nnTF { ##1 } { \dots }
     {
      \exp_not:n { \framebox[#1][#2] { \strut\dotfill } }
     }
     {
      \exp_not:n { \framebox[#1][#2] { \strut$##1$ } }
     }
   }
  \seq_use:Nn \l_rima_boxes_seq { \kern-\fboxrule }
 }
\ExplSyntaxOff

\begin{document}

\rimaboxes{b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\bigskip

\rimaboxes(l){b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\bigskip

\rimaboxes[.3in]{b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\bigskip

\rimaboxes[.3in](r){b_{0},b_{1},b_{2},\dots,b_{st-1},b_{st}}

\end{document}

enter image description here

As you see, the last two examples don't really fit.

2

enter image description here

\documentclass{article}
\usepackage{tabularx}
\setlength\extrarowheight{2pt}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{|*6{>{\centering$}X<{$}|}}
\hline
b_0&b_1&b_2&\cdots&b_{s.t-1}&b_{s.t}\tabularnewline
\hline
\end{tabularx}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .