1

Using restructured text, how can I display two code blocks side by side, so that they can be compared line by line?

Here is an example of what I mean from this similar question for Markdown: How to disply two markdown code blocks side by side

Code in two columns

bad_coder
  • 11,289
  • 20
  • 44
  • 72
shimeji42
  • 313
  • 1
  • 11

1 Answers1

1

Ok, so I found that the following works:

+-------------------------+-------------------------+
|                         |                         |
|.. code-block::          |.. code-block::          |
|                         |                         |
|   # Code example 1      |   # Code example 2      |
|                         |                         |
+-------------------------+-------------------------+

This creates a table with two columns, and puts a code block in each of them. If the two blocks have the same number of lines, they will be aligned to each other. The output looks like this:

enter image description here

If one wants to include an external script, it can be done like this:

+--------------------------------+--------------------------------+
|                                |                                |
|.. literalinclude:: script_1.py |.. literalinclude:: script_2.py |
|                                |                                |
+--------------------------------+--------------------------------+
shimeji42
  • 313
  • 1
  • 11