Is there an easy way to make a pleasing mediawiki table?

14,255

Solution 1

As you wrote, you can edit Mediawiki CSS files. This is the way to go; however, if for some reason you can't use CSS, you can always use Wiki templates that contain cell-specific styling tags.

Solution 2

Do like they do in Wikipedia: create a "prettytable" template (see source; you can skip the fancy <noinclude> stuff) where you put some HTML / CSS, e.g.:

border="1" cellpadding="4" cellspacing="0" style="margin: 1em 1em 1em 0; 
background: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;"

Then use the template like this in your tables; it does a simple "include":

{| {{Prettytable}}
...
|}

The same technique can be used for styling cells. You should find plenty more examples of this in different Wikipedias (and other Wikimedia projects).

Solution 3

You can customise the CSS used via pages in the MediaWiki namespace, for example, MediaWiki:Common.css. There are also skin-specific CSS pages, e.g. MediaWiki:Monobook.css, for the default skin.

Share:
14,255
OwenP
Author by

OwenP

I've been working with WinForms since 2003, including the dark corners of design-time integration. I followed Microsoft through WPF and Silverlight, then decided to try Xamarin Forms for a while. Microsoft followed me this time, but eventually I found myself moving to ASP .NET Core. I go nuts for talking about async patterns in WinForms, but also have spent a lot of time studying and practicing testable design. I've been branching out into HTML/JS lately, and I'm always looking for something interesting to hack at.

Updated on August 06, 2022

Comments

  • OwenP
    OwenP almost 2 years

    I use a MediaWiki instance on a thumb drive to keep track of a ton of stuff. In the past, I've been in a hurry so I haven't had the chance to look for a nice way to make tables, so this syntax has served my purposes well:

    {| border=1
    ...
    |}
    

    Now I want something a little nicer; I'm used to using CSS to make nicer table borders, but I'm not finding a clean way to do this syntax via MediaWiki. Basically, I want a table that looks equivalent to this HTML:

    <table style="border-collapse: collapse">
        <tr>
            <td style="border: 1px solid black">one</td>
            <td style="border: 1px solid black">two</td>
        </tr>
    </table>
    

    Setting border on every cell is going to be difficult. My initial guess is I need to add a table class to a CSS file somewhere; if so, where might the appropriate file be located?

  • OwenP
    OwenP over 15 years
    Oooh, I like this a little better, but in some ways I fail to see how it is advantageous to editing the CSS. For example, if I set the class of the table, I can use CSS to style the rows and cells automatically; with this method, the template has to include the class, which isn't much saved effort.
  • Jonik
    Jonik over 15 years
    One advantage: this can be used simply from Wiki interface, no digging around in Mediawiki installation (+ can use this even if you don't have privileges on the server). But for automatic styling of cells and rows: yes, a CSS class is far handier. So use what suits you better in each situation :)
  • Xonatron
    Xonatron over 12 years
    @OwenP, it's better for those of us who do not have access to the CSS.
  • Harry Wood
    Harry Wood over 10 years
    Yes we did it this way on OpenStreetMap wiki, so you can see it here: wiki.openstreetmap.org/wiki/MediaWiki:Common.css (we define a 'wikitable' class and various other bits n bobs)