Jump to content

Template:Chess diagram/doc

From Wikibooks, open books for an open world

Syntax

[edit source]

There are two standard chess diagram templates:

The syntax is basically the same for both of them.

{{chess diagram
| <alignment> (param #1)
| <header>    (#2) 
| size =
| numbers =
| letters =
| <a8> | <b8> | ... | <h8>  (#3 to ...
| <a7> | <b7> | ... | <h7>
...
| <a1> | <b1> | ... | <h1>  ( ... #66)
| <footer> (#67)
}}

Parameters:

  • <alignment> – defines horizontal alignment (floating) of the whole table, must be tright or tleft (or nothing)
  • <header> – the text which appears above the diagram, may be empty;
  • size - specifies the size of each square in pixels, the default is 26.
  • numbers - specifies whether the rows are numbered. Options are: left, right, both (default) or neither.
  • letters - specifies whether the columns are lettered. Options are: top, bottom, both (default) or neither.
  • <a8>, <b8>, ... <h1> – define corresponding squares of the chessboard, see below;
  • <footer> – the text which appears beneath the diagram, may be empty; optional – can be left out (currently not in the other templates)

A square is defined by the name of piece or empty parameter. The names of the pieces are those given in algebraic notation:

  • k = king
  • q = queen
  • r = rook
  • b = bishop
  • n = knight
  • p = pawn

There are also some fairy chess pieces available:

  • a = archbishop (knight bishop compound)
  • c = chancelor (knight rook compound)
  • f = upside-down king
  • g = upside-down queen
  • m = upside-down rook
  • e = upside-down bishop
  • s = upside-down knight
  • h = upside-down pawn
  • z = champion (for Omega Chess)
  • w = wizard (for Omega Chess)

These letters are combined with either "l" for Light=White, or "d" for Dark=Black. So "kl" is White's king, and "nd" is Black's knight.

An empty square is written either using underscores, spaces, or nothing at all. Two spaces are recommended.

  • <space> = empty square

You can also use "xx" for a cross, "xo" for a black circle on an empty square or "oo" for a white one.

  • xx = cross/x
  • xo = black circle
  • oo = white circle

Numbers can also be added to squares by using "x0" for 0, "x1" for 1, "x2" for 2, ..., "x9" for 9.

  • x0
  • x1
  • x2
  • x3
  • x4
  • x5
  • x6
  • x7
  • x8
  • x9

Examples

[edit source]

In the following examples the rows and columns are numbered. Because any text between "|=" and the next "|" is ignored, numbers and letters can be added without affecting output.

Standard diagram

[edit source]

This diagram is recommended for common use as a main diagram in books on chess openings, endings, games, positions etc. See the corresponding code below.

a b c d e f g h
8a8 black rookb8 black knightc8 black bishopd8 black queene8 black kingf8 black bishopg8 black knighth8 black rook8
7a7 black pawnb7 black pawnc7 black pawnd7 black pawne7 black kingf7 black pawng7 black pawnh7 black pawn7
6a6 black kingb6 black kingc6 black kingd6 black kinge6 black kingf6 black kingg6 black kingh6 black king6
5a5 black kingb5 black kingc5 black kingd5 black kinge5 black pawnf5 black kingg5 black kingh5 black king5
4a4 black kingb4 black kingc4 black kingd4 black kinge4 white pawnf4 white pawng4 black kingh4 black king4
3a3 black kingb3 black kingc3 black kingd3 black kinge3 black kingf3 black kingg3 black kingh3 black king3
2a2 white pawnb2 white pawnc2 white pawnd2 white pawne2 black kingf2 black kingg2 white pawnh2 white pawn2
1a1 white rookb1 white knightc1 white bishopd1 white queene1 white kingf1 white bishopg1 white knighth1 white rook1
a b c d e f g h
The King's Gambit
{{chess diagram
| tright
| 
|= 

 8 |rd|nd|bd|qd|kd|bd|nd|rd|=
 7 |pd|pd|pd|pd|  |pd|pd|pd|=
 6 |  |  |  |  |  |  |  |  |=
 5 |  |  |  |  |pd|  |  |  |=
 4 |  |  |  |  |pl|pl|  |  |=
 3 |  |  |  |  |  |  |  |  |=
 2 |pl|pl|pl|pl|  |  |pl|pl|=
 1 |rl|nl|bl|ql|kl|bl|nl|rl|=
    a  b  c  d  e  f  g  h  

| The King's Gambit
}}

Diagram with both captions

[edit source]
W. Langstaff, Chess Amateur 1922
a b c d e f g h
8a8 black kingb8 black kingc8 black kingd8 black kinge8 black kingf8 black kingg8 black kingh8 black rook8
7a7 black kingb7 black kingc7 black kingd7 black kinge7 black kingf7 black kingg7 black kingh7 black king7
6a6 black kingb6 black kingc6 black kingd6 black kinge6 black kingf6 white bishopg6 black kingh6 white pawn6
5a5 black kingb5 black kingc5 black kingd5 white rooke5 black kingf5 white kingg5 black pawnh5 white pawn5
4a4 black kingb4 black kingc4 black kingd4 black kinge4 black kingf4 black kingg4 black kingh4 black king4
3a3 black kingb3 black kingc3 black kingd3 black kinge3 black kingf3 black kingg3 black kingh3 black king3
2a2 black kingb2 black kingc2 black kingd2 black kinge2 black kingf2 black kingg2 black kingh2 black king2
1a1 black kingb1 black kingc1 black kingd1 black kinge1 black kingf1 black kingg1 black kingh1 black king1
a b c d e f g h
Mate in two.
This problem uses partial retrograde analysis method.

It may be convenient to use this in the articles on chess problems. Please note that in the header and footer you can use bolds or italics. You can also use <br> to break the lines.

{{chess diagram
| tright
| '''W. Langstaff''', ''Chess Amateur'' 1922
|= 

 8 |  |  |  |  |kd|  |  |rd|=
 7 |  |  |  |  |  |  |  |  |=
 6 |  |  |  |  |  |bl|  |pl|=
 5 |  |  |  |rl|  |kl|pd|pl|=
 4 |  |  |  |  |  |  |  |  |=
 3 |  |  |  |  |  |  |  |  |=
 2 |  |  |  |  |  |  |  |  |=
 1 |  |  |  |  |  |  |  |  |=
    a  b  c  d  e  f  g  h  

| '''Mate in two.''' <br> This problem uses ''partial retrograde analysis'' method.
}}

Diagram without captions

[edit source]
a b c d e f g h
8a8 black kingb8 black kingc8 black kingd8 black kinge8 black kingf8 black kingg8 black kingh8 black king8
7a7 black kingb7 black kingc7 black kingd7 black kinge7 black kingf7 black kingg7 black kingh7 black king7
6a6 black kingb6 crossc6 black circled6 crosse6 black kingf6 black kingg6 black kingh6 black king6
5a5 black kingb5 black kingc5 white pawnd5 black kinge5 black kingf5 black kingg5 black kingh5 black king5
4a4 black kingb4 black kingc4 black kingd4 black kinge4 black kingf4 black circleg4 black kingh4 black king4
3a3 black kingb3 black kingc3 black kingd3 black kinge3 crossf3 black circleg3 crossh3 black king3
2a2 black kingb2 black kingc2 black kingd2 black kinge2 black kingf2 white pawng2 black kingh2 black king2
1a1 black kingb1 black kingc1 black kingd1 black kinge1 black kingf1 black kingg1 black kingh1 black king1
a b c d e f g h

See the corresponding code below. If you don't want the captions, just remove them, but don't delete the second "|" pipe character for the caption above; it is possible to delete the last pipe for the longer caption below.

The diagram floats to the left to illustrate the use of the first parameter.

{{chess diagram
| tleft
| 
|= 

 8 |  |  |  |  |  |  |  |  |=
 7 |  |  |  |  |  |  |  |  |=
 6 |  |xx|xo|xx|  |  |  |  |=
 5 |  |  |pl|  |  |  |  |  |=
 4 |  |  |  |  |  |xo|  |  |=
 3 |  |  |  |  |xx|xo|xx|  |=
 2 |  |  |  |  |  |pl|  |  |=
 1 |  |  |  |  |  |  |  |  |=
    a  b  c  d  e  f  g  h  
}}

Small diagram

[edit source]

This one may be useful in pages with many diagrams. It uses another template named {{chess diagram small}}.

The small diagrams can have header, too.

a b c d e f g h
8 a8 black rook b8 black king c8 black king d8 black queen e8 black king f8 black rook g8 black king h8 black king 8
7 a7 black pawn b7 black pawn c7 black king d7 black king e7 black pawn f7 black pawn g7 black bishop h7 black pawn 7
6 a6 black king b6 black knight c6 black pawn d6 black king e6 black king f6 black knight g6 black pawn h6 black king 6
5 a5 black king b5 black king c5 white queen d5 black king e5 black king f5 black king g5 white bishop h5 black king 5
4 a4 black king b4 black king c4 black king d4 white pawn e4 white pawn f4 black king g4 black bishop h4 black king 4
3 a3 black king b3 black king c3 white knight d3 black king e3 black king f3 white knight g3 black king h3 black king 3
2 a2 white pawn b2 white pawn c2 black king d2 black king e2 black king f2 white pawn g2 white pawn h2 white pawn 2
1 a1 black king b1 black king c1 black king d1 white rook e1 white king f1 white bishop g1 black king h1 white rook 1
a b c d e f g h
The position after 11. Bg5.
{{chess diagram small
| tright
| 
|= 

 8 |rd|  |  |qd|  |rd|kd|  |=
 7 |pd|pd|  |  |pd|pd|bd|pd|=
 6 |  |nd|pd|  |  |nd|pd|  |=
 5 |  |  |ql|  |  |  |bl|  |=
 4 |  |  |  |pl|pl|  |bd|  |=
 3 |  |  |nl|  |  |nl|  |  |=
 2 |pl|pl|  |  |  |pl|pl|pl|=
 1 |  |  |  |rl|kl|bl|  |rl|=
    a  b  c  d  e  f  g  h  

| The position after 11. Bg5.
}}