0

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:

output screenshot

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

3 Answers 3

1

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}

enter image description here

2
  • Works, thanks! That screenshot is not the \makebox version though, is it?
    – Anakhand
    Commented Mar 13, 2018 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
    Commented Mar 13, 2018 at 16:30
1

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

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}
\noindent\qquad
\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}

enter image description here

More simply:

\documentclass{article}
\usepackage{framed}

\begin{document}

\begin{framed}
\ttfamily\noindent\qquad
\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}

You must log in to answer this question.

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