# Custom positioning of elements (relative to other object)

Is there a way to position text objects relative to other objects?

My current code:

\begin{framed}
\begin{verbatim}
10
6.666666666666667
5.9259259259259265
5.83088884457784
\end{verbatim}
\ \ \ \ \ \ $\vdots$
\begin{verbatim}
5.818578011589186
5.818578011589186
5.818578011589186
\end{verbatim}
\ \ \ \ \ \ $\vdots$
\end{framed}


I am placing blank spaces in front of the \vdotsbecause I want them to be centered relative to the numbers:

Is there an elegant way to do this (i.e. without having to guess the amount of spaces needed, etc.)?

You can use the calc package to estimate the width of the longest line and pass that width to \makebox to center the \vdots within that width, see below.

\documentclass[12pt,a4paper]{article}
\usepackage{framed,calc}
\begin{document}

\begin{framed}
\begin{verbatim}
10
6.666666666666667
5.9259259259259265
5.83088884457784
\end{verbatim}
\makebox[\widthof{5.9259259259259265}]{$\vdots$}
\begin{verbatim}
5.818578011589186
5.818578011589186
5.818578011589186
\end{verbatim}
\makebox[\widthof{5.9259259259259265}]{$\vdots$}
\end{framed}
\makebox[\widthof{5.9259259259259265}]{$\vdots$}
\end{framed}

\end{document}


• Works, thanks! That screenshot is not the \makebox version though, is it? – Anakhand Mar 13 '18 at 16:19
• I've updated it according to the code. By default, verbatim takes all spaces literally, so, if you indent a line it will appear indented in the output. – AboAmmar Mar 13 '18 at 16:30

If you need to center something in a column and you are searching an elegant way, you can use \halign:

\halign{\tt#\unskip\hfil\cr
10                  \cr
6.666666666666667   \cr
5.9259259259259265  \cr
5.83088884457784    \cr
\hfil $\vdots$      \cr
5.818578011589186   \cr
5.818578011589186   \cr
5.818578011589186   \cr
\hfil $\vdots$      \cr
}

\bye

• Thanks, this addresses the problem directly. Can I then put the numbers in a verbatim environment? – Anakhand Mar 13 '18 at 16:28
• Why in verbatim envionment? – wipet Mar 13 '18 at 16:30
• It's a Python program's output, and want to show it with this font format (code-like) – Anakhand Mar 13 '18 at 16:48
• This font format is realized by \tt. – wipet Mar 13 '18 at 18:23

I'm not sure what verbatim is for; anyway, with fancyvrb you have BVerbatim that makes a box which tabular can measure.

\documentclass{article}
\usepackage{framed,fancyvrb}

\begin{document}

\begin{framed}
\begin{tabular}{@{}l@{}}
\begin{BVerbatim}[codes={\baselineskip=\normalbaselineskip}]
10
6.666666666666667
5.9259259259259265
5.83088884457784
\end{BVerbatim}
\\
\multicolumn{1}{@{}c@{}}{$\vdots$} \\[6pt]
\begin{BVerbatim}[codes={\baselineskip=\normalbaselineskip}]
5.818578011589186
5.818578011589186
5.818578011589186
\end{BVerbatim}
\\
\multicolumn{1}{@{}c@{}}{$\vdots$}
\end{tabular}
\end{framed}

\end{document}


More simply:

\documentclass{article}
\usepackage{framed}

\begin{document}

\begin{framed}
\begin{tabular}{@{}l@{}}
10 \\
6.666666666666667 \\
5.9259259259259265 \\
5.83088884457784 \\
\multicolumn{1}{@{}c@{}}{$\vdots$} \\[6pt]
5.818578011589186 \\
5.818578011589186 \\
5.818578011589186 \\
\multicolumn{1}{@{}c@{}}{$\vdots$}
\end{tabular}
\end{framed}

\end{document}