1

How to draw something like below in latex:

enter image description here

  • 1
    Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. – user31729 Aug 5 '15 at 11:01
  • Very much related: tex.stackexchange.com/questions/168035/… – Steven B. Segletes Aug 5 '15 at 11:04
3

Here is a first cut, based on my answer at Matrix decomposition dimensions diagram.

Syntax for a box is \matbox{rows}{row-label}{columns}{column-label}{box-title}. For example, \matbox{3}{dimensions}{8}{documents}{...} creates a box of 3 rows labeled "dimensions" and 8 columns labeled "documents".

To allow for the complex box title, I introduce \titlebox[width]{primary-math-label}{sub-text}. Boxes may be vertically shifted with \raiserows{row-shift}{box-to-be-shifted}. The row-shift should be set to 1/2 the difference of the row height of the matrices. For example, here the tall matrices are 7 rows, the small are 3 rows high. Thus the shift is .5(7-3) = 2.

\documentclass{article}
\usepackage{stackengine,graphicx}
\stackMath
\newlength\matfield
\newlength\tmplength
\def\matscale{1.}
\newcommand\dimbox[3]{%
  \setlength\matfield{\matscale\baselineskip}%
  \setbox0=\hbox{\vphantom{X}\smash{#3}}%
  \setlength{\tmplength}{#1\matfield-\ht0-\dp0}%
  \fboxrule=1pt\fboxsep=-\fboxrule\relax%
  \fbox{\makebox[#2\matfield]{\addstackgap[.5\tmplength]{\box0}}}}
\newcommand\raiserows[2]{%
   \setlength\matfield{\matscale\baselineskip}%
   \raisebox{#1\matfield}{#2}}
\newcommand\matbox[5]{
  \raisebox{2.3ex}{\rotatebox[origin=center]{90}{\scalebox{.45}{#2}}}\,%
  \stackon{\dimbox{#1}{#3}{#5}}{\scalebox{.45}{#4}}}
\newcommand\titlebox[3][30ex]{\stackanchor{#2}{\scalebox{.45}{\parbox{#1}{\centering #3}}}}
\begin{document}
\[\renewcommand\matscale{.6}
\matbox{7}{words}{8}{documents}{%
  \titlebox[20ex]{X}{transformed word-document co-occurance matrix}} 
= 
\matbox{7}{words}{3}{dimensions}{\titlebox[10ex]{U}{word space}} 
\raiserows{2}{\matbox{3}{dimensions}{3}{dimensions}{\titlebox{D}{weights}}} 
\stackunder[6pt]{%
  \raiserows{2}{\matbox{3}{dimensions}{8}{documents}{\titlebox{V^T}{document space}}}%
}{\scalebox{.6}{LSA}}
\]
\end{document}

enter image description here

With the default \matscale=1, one row will occupy a height of 1\baselineskip. Thus, the box sizes may be globally changed by resetting \matscale. In the above MWE, I reset the value to .6, so that 7 rows occupies .6(7) = 4.2\baselineskip of vertical distance. The numbers of rows and columns can be set to actual matrix values, which can be very large, as long as the \matscale is appropriately reduced in tandem with the size of the row/column values.

Below is the appearance when \matscale is changed to 0.8:

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.