# Custom printing of struct?

**URL:** <https://discourse.julialang.org/t/custom-printing-of-struct/73812>\
**Category:** General Usage\
**Created:** [December 30, 2021, 11:36am UTC](https://discourse.julialang.org/t/custom-printing-of-struct/73812 "2021-12-30T11:36:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [December 30, 2021, 11:36am UTC](https://discourse.julialang.org/t/custom-printing-of-struct/73812/1 "2021-12-30T11:36:46Z")

</div>

If I have a struct with some arbitrary values, how can I make a function, such that when I call “print” or “println” it will print the struct in the way I define?

Kind regards

---

<div class="post-metadata">

**Author:** ![eliascarv](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eliascarv/32/22152_2.png) [@eliascarv](https://discourse.julialang.org/u/eliascarv)\
**Post date:** [December 30, 2021, 12:08pm UTC](https://discourse.julialang.org/t/custom-printing-of-struct/73812/2 "2021-12-30T12:08:22Z")

</div>

You can overload the `Base.show(io::IO, obj::MyType)` function.  
Example:

 ![base_show](https://global.discourse-cdn.com/julialang/original/3X/6/a/6a7db284c02bc9d586b98f1bc87d6cbc5b711459.png)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 30, 2021, 1:41pm UTC](https://discourse.julialang.org/t/custom-printing-of-struct/73812/3 "2021-12-30T13:41:38Z")

</div>

See the manual on [custom pretty printing](https://docs.julialang.org/en/v1/manual/types/#man-custom-pretty-printing).

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [December 30, 2021, 1:50pm UTC](https://discourse.julialang.org/t/custom-printing-of-struct/73812/4 "2021-12-30T13:50:52Z")

</div>

Thanks to both of you 😊 Works as I want now!

Kind regards

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [December 30, 2021, 3:30pm UTC](https://discourse.julialang.org/t/custom-printing-of-struct/73812/5 "2021-12-30T15:30:28Z")

</div>

Also take a look at [MechanicalRabbit/PrettyPrinting.jl: Julia library for optimal formatting of composite data structures (github.com)](https://github.com/MechanicalRabbit/PrettyPrinting.jl)
