Template:Center/doc
{{#ifeq:doc |doc
|
{{#ifeq:show |show
|
40px | This is a documentation subpage for Template:Center. It contains usage information, categories and other content that is not part of the original {{#if: |{{{text2}}} |{{#if: |{{{text1}}} |{{#ifeq:Template |User |template template page |{{#if:Template |template page|article}}}}}}}}. |
}}{{#if: | | {{#ifexist:Template:Center | [[Category:{{#switch:Template |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]] | }} }} | }}
40px | This {{
|Module=Lua module
|#default=template
}} is used on {{#if: 550000+ |550,000+|a very large number of}} pages.
|Module=module |#default=template }} should first be tested in its [[{{
| doc | sandbox = Template:Center | #default = Template:Center/doc }}/sandbox|/sandbox]] or [[{{
| doc | sandbox = Template:Center | #default = Template:Center/doc }}/testcases|/testcases]] subpages{{
|Module=. |#default= or in your own user subpage. }} The tested changes can then be added to this page in a single edit. Please consider discussing any changes {{#if:|at [[{{{2}}}]]|on the [[{{
| doc | sandbox = Template talk:Center | #default = Template talk:Center/doc }}|talk page]]}} before implementing them. |
A simple template to center-align content in tables and other places. Be aware that the center class is appllied to this template, which means every element within the template has its left and right margins set to auto. This may harm some templates.
Example
{{#if: ||+ {{{title}}}}} {{#if: |Markup | Renders as
}}{{#if: {{Center|Hello world!}} |
|
{{Center|Hello world!}} |
Hello world! {{#if:Hello world!||}}
}}{{#if: | | |
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}}{{#if: | | ||
}} | ||
To do this without a template, simply use the following code:
{{#switch:pair
|c|close =
|e|empty|s|single|v|void
|o|open
|p|pair = <div{{#if:class="center" style="width:auto; margin-left:auto; margin-right:auto;"| class="center" style="width:auto; margin-left:auto; margin-right:auto;"}}
}}{{#switch:pair
|c|close =
|e|empty|s|single|v|void = />
|o|open = >
|p|pair = {{#ifeq:div|!--||>}}...
}}{{#switch:pair
|e|empty|s|single|v|void
|o|open =
|c|close
|p|pair = {{#ifeq:div|!--|-->|</div>}}
}}
To center a table, see Help:TABLECENTER.
Table
Using {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|
}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:l|: |Left |{{#switch:
| = Template:{{#if:left|Left|Center/doc}}
| #default = {{#if:left|Left|Template:Center/doc}}
}}}}|}}{{#if: |{}}{{#if:left|left|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |
}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |
}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:c|: |Center |{{#switch:
| = Template:{{#if:center|Center|Center/doc}}
| #default = {{#if:center|Center|Template:Center/doc}}
}}}}|}}{{#if: |{}}{{#if:center|center|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |
}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |
}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:r|: |Right |{{#switch:
| = Template:{{#if:right|Right|Center/doc}}
| #default = {{#if:right|Right|Template:Center/doc}}
}}}}|}}{{#if: |{}}{{#if:right|right|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |
}}{{#if:{{#if:||yes}} |}}
Header text
Left
Left
}} || Center{{#if:Center||}} || {{safesubst:#ifeq:Right|Right
Right
}}
Using {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|: |Align |{{#switch:
| = Template:{{#if:align|Align|Center/doc}}
| #default = {{#if:align|Align|Template:Center/doc}}
}}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |
}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |
}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|: |Align |{{#switch:
| = Template:{{#if:align|Align|Center/doc}}
| #default = {{#if:align|Align|Template:Center/doc}}
}}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |
}}{{#if:{{#if:||yes}} |}} / {{#if:{{#if:||yes}} |}}{{#if:yes | |{{#if:|}} }}{{#if: |}}{{#if: |}}{{#if: | |{{}}{{#if: |subst:}}{{#if: |
}}{{#if:yes || {{#if: |{}}[[:{{#ifeq:a|: |Align |{{#switch:
| = Template:{{#if:align|Align|Center/doc}}
| #default = {{#if:align|Align|Template:Center/doc}}
}}}}|}}{{#if: |{}}{{#if:align|align|{{#ifeq:Template|Template|Center/doc|Template:Center/doc}}}}{{#if: |}}}{{#if:yes | |]]{{#if: |}}}}}{{#if: |}}{{#if: |}}{{#if: |}}{{#ifeq:¬|¬ | ||{{{2}}}}}{{#ifeq:¬|¬ | ||{{{3}}}}}{{#ifeq:¬|¬ | ||{{{4}}}}}{{#ifeq:¬|¬ | ||{{{5}}}}}{{#ifeq:¬|¬ | ||{{{6}}}}}{{#ifeq:¬|¬ | ||{{{7}}}}}{{#ifeq:¬|¬ | ||{{{8}}}}}{{#ifeq:¬|¬ | ||{{{9}}}}}{{#ifeq:¬|¬ | ||{{{10}}}}}{{#ifeq:¬|¬ | ||{{{11}}}}}{{#if: ||…}}{{#if: |}}{{#if: | |}}}}{{#if: |}}{{#if:yes |
}}{{#if:{{#if:||yes}} |}}
Header text
{{#switch: left
left = Left
right = Left
center = Left {{#if:Left
}}
#default = Error in Template:Align: the alignment setting "left" is invalid.
}} || {{#switch: center
left = Center
right = Center
center = Center {{#if:Center
}}
#default = Error in Template:Align: the alignment setting "center" is invalid.
}} || {{#switch: right
left = Right
right = Right
center = Right {{#if:Right
}}
#default = Error in Template:Align: the alignment setting "right" is invalid.
}}
See also