0

I try to include code-clocks in tables in the docstrings that are interpreted by Sphinx. I tried the following:

+-------------------------------------------+---------------------------------------------------+------------------------------------+
| Method 1                                  | Method 2                                          | Method 3                           |
+===========================================+===================================================+====================================+
| .. code-block::                           | .. code-block::                                   | .. code-block::                    |
|                                           |                                                   |                                    |
|    "num_magnet_segments_all": 3           |    "num_magnet_segments_all": 3,                  |    "num_magnet_segments_all": 3,   |
|                                           |    "num_magnet_segments": {                       |    "magnet_segment_widths": {      |
|                                           |              "Rotor.Magnet3_North": 5,            |               "82": [3, 9],        |
|                                           |              "Rotor.Magnet3_South": 5}            |               "96": 10}            |
+-------------------------------------------+---------------------------------------------------+------------------------------------+

This basically works but the code inside the blocks is centered instead of left-aligned. The whole table is centered by the way but the ordinary text within the table is left-aligned as expected. How can I force the code-blocks to output what I write instead of re-aligning the code?

enter image description here

  • Related *[How to right-align columns content in reStructuredText simple tables?](https://stackoverflow.com/q/7348208)*. There are [a few more threads](https://stackoverflow.com/search?tab=votes&q=%5bpython-sphinx%5d%20table%20is%3aq%20align) on the subject. – bad_coder Nov 12 '20 at 17:01
  • 1
    Which theme are you using? Some themes do not exhibit this behavior. I could not replicate the issue with basic or nature themes. – Steve Piercy Nov 13 '20 at 05:04
  • 1
    Thank you for your answers. They brought me to the right direction. I had used the 'haiku' theme and this behavior seems to be explicitly coming from this. I have now switched to 'classic' with "a lot of" customizing. This was a pleasing solution. – monoceros84 Nov 13 '20 at 13:59

0 Answers0