0

I am honing my skills in LaTeX by rewriting random articles from the internet. One such article is given below:

enter image description here

The first one looks like a table that spans the whole paragraph width, while the second is encapsulated in a figure not to mention it seems like the content in the second one is in verbatim. I wanted to know how to accomplish such an arrangement of objects in the document.

1 Answers1

1

Here is a start as there are numerous ways of achieving any of the structures you show:

  • You can use a tabularx or a tabular with properly-spaced out columns (even if they include verbatim content). tabularx's verbatim concerns can be removed in a number of ways - below I've placed every active character <chr> with \string<chr> to let it print within \ttfamily.

  • You can play around with spacing above/below the \hlines. \struts here can help. See Column and row padding in tables.

  • The second figure is just a float. It can contain anything really, even a tabular. Similarly, a table float can contain an image (using \includegraphics, say). The float is just a structure that defines a moving (or floating) box that you can put content in. It also specifies the caption title as either Figure or Table (which can be changed a well).

enter image description here

\documentclass{article}

\usepackage{tabularx}

\begin{document}

\noindent \begin{tabularx}{\linewidth}{@{} X X @{}} \hline $\frac{1}{2}$ is a fraction & \ttfamily\string$\string\frac\string{1\string}\string{2\string}\string$ is a fraction \ \hline \end{tabularx}

\bigskip

\noindent \begin{tabular}{@{} p{\dimexpr.5\linewidth-\tabcolsep} p{\dimexpr.5\linewidth-\tabcolsep} @{}} \hline $\frac{1}{2}$ is a fraction & \verb|$\frac{1}{2}$ is a fraction| \ \hline \end{tabular}

\begin{figure}[h] \centering \begin{tabular}{ l } \hline \verb|\documentclass{article}| \ \verb|\begin{document}| \ \verb|This is a simple example to start with \LaTeX.| \ \verb|\end{document}| \ \verb|The first task| \ \hline \end{tabular} \caption{A Simple \LaTeX{} document.} \end{figure}

\end{document}

Werner
  • 603,163
  • Done! I used struts for the vertical padding. I preferred the 0 width rule method rather than using arraystretch as that would have effected all the rows in the table. Also verb was the perfect solution for the verbatim issue, still wish there was a way to use verbatim perhaps momentarily switching to monospace using a macro should work. Thanx Again! – Kluivert Correia Jun 01 '21 at 18:29