Brian Grinter
Brian Grinter

Reputation: 93

Place a table in an Ordered List in Mediawiki

I'm trying to place a table inline in an ordered list in Mediawiki however it breaks my numbering. What I want is

1. A1
1.1 B1
1.2 B2
my table
2. A2

but what I get is

1. A1
1.1 B1
1.2 B2
my table
1. A2

Basic markup I'm using is;

# A1
## B1
## B2
my table
#A2

Upvotes: 7

Views: 1168

Answers (4)

Kevin E
Kevin E

Reputation: 3206

Building on Sam's (already fine) answer:

As mentioned on the MediaWiki Support desk, you can use HTML lists to make the table part of B2:

<ol>
  <li> A1
    <ol>
      <li> B1
      <li> B2
{| class=wikitable
 ! Header
 |-
 | Data
 |}
    </ol>
  <li> A2
</ol>

The indentation is not required, but adding leading spaces for alignment makes the structure easier to comprehend visually.

Alternatively, you can use an HTML table within the wikitext list. Note that MediaWiki doesn't currently recognize <thead> or <tbody>, so omit those.

# A1
## B1
## B2 <table class=wikitable><tr><th>Header</th></tr><tr><td>Data</td></tr></table>
# A2

As noted in wakalaka's answer, you can (ab)use HTML comments to spread the table over multiple lines, if you wish.

The complexity of your list versus the complexity of your table will probably dictate which method you choose. A benefit of the latter solution is you can hide the gnarly HTML in a template or subpage and transclude it into the list with the expected alignment, which is not possible with the former (see the screenshot below).

Results of each of the three methods of embedding a table within a list in MediaWiki

Upvotes: 1

wakalaka
wakalaka

Reputation: 533

As alternative to Sam Wilson's answer you can keep wiki markup for ordered list, but use HTML markup for table instead. To do so you'll need to replace all line breaks within table markup with HTML comments, like this:

# A
# B
## BB
## CC
### <table><!--
--><tr><!--
-- --><td>dawda</td><td>dawd</td><!--
--></tr><!--
--><tr><!--
-- --><td>dawda</td><td>dawd</td><!--
--></tr><!--
--></table>
## EE
## FF
# G

Note that ‎<thead>‎, ‎<tbody> and ‎<tfoot> are not supported.

Upvotes: 2

Brian Grinter
Brian Grinter

Reputation: 93

Colleague worked out the answer so I thought I'd share it here - simply a tweak to the common.css file

}
.list_numbered > ol:first-of-type, .list_numbered > ol ol {
    counter-reset: item;
}

Upvotes: 1

Sam Wilson
Sam Wilson

Reputation: 4512

I don't think it's possible with wikitext, but you can use HTML lists to make the table part of B2:

<ol>
<li> A1 <ol>
<li> B1
<li> B2
{|class=wikitable
! Header
|-
| Data
|}
</ol>
<li>A2
</ol>

The other thing that can help in situations like this (although not, it seems, this particular one) is the value parameter for list items.

Upvotes: 5

Related Questions